Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-19379

CPPQuickFixes, Complete Switch Statement doesn't work with typedef'ed enum

    XMLWordPrintable

Details

    Description

      When using QTCreator with C the following code doesn't allow to make use of the "Complete Switch Statement" refactoring option :

      typedef enum value_bug
      {
           VALUE_BUG_1,
           VALUE_BUG_2,
           VALUE_BUG_3,
           VALUE_BUG_4,
      } value_bug_t;
      
      int test_bug(int argc, char **argv)
      {
           value_bug_t value_bug = VALUE_BUG_1;
           // right click on the switch keyword, refactor menu only has "Rename Symbol Under Cursor"
           switch (value_bug)
           {
           }
      }

      The following code allows the "Complete Switch Statement"

      enum value_nobug
      {
           VALUE_NOBUG_1,
           VALUE_NOBUG_2,
           VALUE_NOBUG_3,
           VALUE_NOBUG_4,
      };
      
      int main_no_bug(int argc, char **argv)
      {
           enum value_nobug ok = VALUE_NOBUG_1;
           // right click on the switch keyword, refactor menu has "Complete Switch Statement"
           switch (ok)
           {
           }
      }
      

      Clicking on the "Complete Switch Statement" will generate the following code :

      enum value_nobug
      {
           VALUE_NOBUG_1,
           VALUE_NOBUG_2,
           VALUE_NOBUG_3,
           VALUE_NOBUG_4,
      };
      
      int main_no_bug(int argc, char **argv)
      {
           enum value_nobug ok = VALUE_NOBUG_1;
           switch (ok)
           {
           case VALUE_NOBUG_1:
                break;
           case VALUE_NOBUG_2:
                break;
           case VALUE_NOBUG_3:
                break;
           case VALUE_NOBUG_4:
                break;  
           }
      }
      

      The difference being the use of typedef to define an enumerated type in the non-working case and the use of the enum type

      Debugging Entry point :

      https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/plugins/cppeditor/cppquickfixes.cpp?h=9ad760efda424105dc5aee91b94d07405603489a#n2341

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            chli Christophe Aeschlimann
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes