CLion 2019.2 Help

Safe Delete

The Safe Delete refactoring lets you safely remove files from the source code. This refactoring prevents you from uncontrolled deleting of declarations that have usages in the source code.

To make sure that deletion is safe, CLion looks for the usages of the file being deleted. If such usages are found, you can explore them and make the necessary corrections in your code before the symbol is actually deleted.

  1. Select the item to be deleted.

  2. Do one of the following:
    • Press Alt+Delete.

    • Select Refactor | Safe Delete from the main or the context menu.

    • Select Refactor | Refactor This from the main menu Ctrl+Shift+Alt+T, and select Safe Delete.

  3. In the Safe Delete dialog, select the necessary options and click OK:

    Safe Delete dialog

  4. If the refactoring is potentially unsafe, the Usages Detected dialog opens.

    Usages Detected dialog

    • View Usages. Click this button to see where in your code the item you are about to delete is used. As a result, the Find tool window opens.

      Find tool window

      Analyze your code and make the necessary corrections. Then click Do Refactor. (If you want to rerun the refactoring from its start, click Rerun Safe Delete. CLion will check if the refactoring is safe once more.)

    • Delete Anyway. Click this button to delete the item without looking at its usages.

Safe Delete for files and CMake

When deleting files, in case these files are referenced in CMake commands, CLion performs Safe Delete: files and references are deleted, and CMake is reloaded (if autoreload is turned on).

Safe Delete for files and their references in CMakeLists.txt is supported for the following commands:

  • add_executable();

  • add_library();

  • set();

  • add_custom_target_command();

  • fltk_wrap_ui();

  • qt_wrap_cpp();

  • qt_wrap_ui():

  • set_property();

  • set_source_files_properties();

  • try_compile().

Last modified: 3 October 2019