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

Syntax highlight / autocomplete gets confused when things look like function type declarations.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • Qt Creator 4.14.0, Qt Creator 6.0.2
    • C/C++/Obj-C++ Support
    • None
    • Windows 10 64-bit, observed in Creator 4.14.x and 6.0.2, MinGW 8.1.0 64-bit
    • Windows

    Description

      When statements that are not function type declarations look like function type declarations, the parser gets confused. These are statements of the form:

      identifier1 ( identifier2 ) ( parameters? ) ;

      Here are three examples (many more can be constructed). Given the following definitions (complete example source attached):

      constexpr int SomeValue = 0;
      
      struct SomeClass {
          explicit SomeClass (int) { }
          void operator () (int=0) { }
      };
      
      enum SomeEnum { ValueA, ValueB, ValueC, ValueD };
      

      Example 1 shows this popping up when invoking a closure:

      void example1 () {
          auto closure = [] (int) {
              return [] () {
              };
          };
          closure(SomeValue)(); // <-- here
      }
      

      The parser then believes SomeValue is a function type (no parameters, return type "closure").

      Also note that "SomeValue" and "closure" are underlined with the "unused" marker. Similar behavior occurs in the rest of the examples as well.


      Example 2 shows this with a class constructor followed by an invocation of a parentheses operator:

      void example2 () {
          SomeClass(SomeValue)();
      }
      

      Example 3 is a clearer example of the effect it has on syntax highlighting, and also demonstrates misparsing a parameter list:

      void example3 (SomeEnum x) {
          switch (x) {
          case ValueA:
          case ValueB:
          case ValueC:
          case ValueD: ;
          }
          SomeClass(ValueB)(ValueD);
      }
      

      The parser treats "ValueB" as a function that takes a "ValueD" and returns a "SomeClass", and fails to color "ValueB" in the preceding switch statement. Additionally, when the cursor is positioned on ValueB, the little gray reference highlighter does not appear in the enum value list itself, showing that the association between "ValueB" and the enum has been lost:


      And a Bonus Example shows the parser treating it as a function type with two overloads:

      void bonus () {
          auto closure = [] (int) {
              return [] () {
              };
          };
          closure(SomeValue)();
          SomeClass(SomeValue)();
      }
      

      Attachments

        1. example1.png
          example1.png
          27 kB
        2. example2.png
          example2.png
          24 kB
        3. example3.gif
          example3.gif
          37 kB
        4. example3.png
          example3.png
          50 kB
        5. example4.gif
          example4.gif
          36 kB
        6. rx.png
          rx.png
          137 kB
        7. test.cpp
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kandeler Christian Kandeler
            jasonc Jason Cipriani
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes