Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Qt Creator Code Model error on legal attribute
QtWS25 Last Chance

Qt Creator Code Model error on legal attribute

Scheduled Pinned Locked Moved Solved C++ Gurus
11 Posts 4 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JonB
    wrote on 7 Sept 2024, 12:12 last edited by
    #1

    I could have posted this to Qt Tools Creator category, but I'm asking stuff in C++ Gurus so this seems just as good a place.

    Creator 13.0, but has always happened on previous Creator versions, I am just getting around to reporting this now. gcc 13.2. -std=gnu++1z (C++ 17), -Wall -Wextra. I cannot find a "switch-case-fallthrough" source code annotation which Creator does not think is an error and so red-underlines it in text editor.

    Note that I cannot use clang/clangd Code Model. I have switched that off in Creator and unloaded that plugin. So whatever Creator's "internal" Code Model is being used. This might be different if it were using clang, I have not/cannot test, but I would like it to work correctly without clang anyway.

    Code:

    switch (...)
    {
        case FIRST:
            ...
            [[fallthrough]]
        case SECOND:
            ...
    }
    

    This is correct code per C++17, C++ attribute: fallthrough (since C++17). It compiles with all warnings on. Creator red-underlines this with tooltip expected token ';' got '["``. Changing to [[gnu::fallthrough]] or [[clang::fallthrough]] does not help.

    Shouldn't Creator's internal code model at least accept [[fallthrough]] which I think is just C++ 17 without special extensions? Should I report this? How do you annotate your case-fallthroughs? Maybe you use clang code model, does something work there?

    S 1 Reply Last reply 9 Sept 2024, 08:03
    0
    • J Offline
      J Offline
      JonB
      wrote on 9 Sept 2024, 09:26 last edited by JonB 9 Sept 2024, 09:43
      #11

      UPDATE/CORRECTION

      I tried again with switching Use clangd on and off. Somehow it seems it didn't "take" right formerly. Now I do see different behaviour. I find that sometimes when I start Creator, it warns me I have don't have enough memory for clangd, I selected "Enable anyway", it still red-underlines [[fallthrough]];. Then I go to Preferences, switch off clangd and then switch it back on, that clears the complaint. It seems I have to switch off and back on every time to make it work. Sigh....

      With clangd switched on I can use any of the [[fallthrough]]; annotations which get through gcc compiler and code editor does not red underline them. Q_FALLTHROUGH() macro still requires a blank line without clangd, but works without blank line with clangd. Fair enough, @aha_1980 has warned me that it will be "problematic* with the internal code model rather than clangd.

      So all in all I can now use [[fallthrough]]; in my code with clangd, that is apparently "standard" C++ 17 so I accept that.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 7 Sept 2024, 12:41 last edited by
        #2

        Shouldn't Creator's internal code model at least accept [[fallthrough]] which I think is just C++ 17 without special extensions?

        No.

        Should I report this?

        It won't be fixed.

        Qt has to stay free or it will die.

        J 1 Reply Last reply 7 Sept 2024, 13:01
        0
        • A aha_1980
          7 Sept 2024, 12:41

          Shouldn't Creator's internal code model at least accept [[fallthrough]] which I think is just C++ 17 without special extensions?

          No.

          Should I report this?

          It won't be fixed.

          J Offline
          J Offline
          JonB
          wrote on 7 Sept 2024, 13:01 last edited by
          #3

          @aha_1980
          Fair enough if you say so :)

          So at least without the clang code model is there any annotation I can put in my code allowing case-fallthrough which compiles without warning but does not cause Creator to mark it as erroneous? Are you saying there would be something if I used the clang code model? If the answer is "No" to both that seems pretty bad, no?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 7 Sept 2024, 17:17 last edited by aha_1980 9 Jul 2024, 17:18
            #4

            The internal code model does not understand much of post C++11 code, so such attributes may be problematic.

            At least gcc seems to honor the // fall through comment, which is primary thought for plain C, but also works in C++. But be careful to write it correctly, its just a comment, no keyword.

            The clang code model should accept all attributes, but does not necessarily warn if [[fallthrough]] is missing. Why? I don't know.

            PS: "will not be fixed" means, you can provide patches and they may be accepted, but noone will actively work on it.

            Qt has to stay free or it will die.

            J 1 Reply Last reply 7 Sept 2024, 18:19
            1
            • A aha_1980
              7 Sept 2024, 17:17

              The internal code model does not understand much of post C++11 code, so such attributes may be problematic.

              At least gcc seems to honor the // fall through comment, which is primary thought for plain C, but also works in C++. But be careful to write it correctly, its just a comment, no keyword.

              The clang code model should accept all attributes, but does not necessarily warn if [[fallthrough]] is missing. Why? I don't know.

              PS: "will not be fixed" means, you can provide patches and they may be accepted, but noone will actively work on it.

              J Offline
              J Offline
              JonB
              wrote on 7 Sept 2024, 18:19 last edited by JonB 9 Jul 2024, 18:20
              #5

              @aha_1980
              All clear, thanks.

              The internal code model does not understand much of post C++11 code,

              Ah! That explains a lot.

              The clang code model should accept all attributes

              But it doesn't accept the 4GB I have allocated to the VM as being enough for its ravenous habits. And Creator 13 disables it. Do you know just how much RAM it does want when I'm going to write a Hello world program?! Honestly if it can't do it when the compiler has enough space to run I give up

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 7 Sept 2024, 18:37 last edited by
                #6

                Ah, I didn't know there is a hard 4 GB limit now.

                Well for this case, you really have to ask the maintainers. But if they think, 4GB is not enough, they might have their statistics.

                The rule of thumb is to have 1 GB RAM per CPU core, as parallel compiling might take this memory. All of my machines have this or more and I have to admit that Clangd works much better than the first Clang Code Model versions. It's not perfect yet, but most often usable :)

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • J JonB
                  7 Sept 2024, 12:12

                  I could have posted this to Qt Tools Creator category, but I'm asking stuff in C++ Gurus so this seems just as good a place.

                  Creator 13.0, but has always happened on previous Creator versions, I am just getting around to reporting this now. gcc 13.2. -std=gnu++1z (C++ 17), -Wall -Wextra. I cannot find a "switch-case-fallthrough" source code annotation which Creator does not think is an error and so red-underlines it in text editor.

                  Note that I cannot use clang/clangd Code Model. I have switched that off in Creator and unloaded that plugin. So whatever Creator's "internal" Code Model is being used. This might be different if it were using clang, I have not/cannot test, but I would like it to work correctly without clang anyway.

                  Code:

                  switch (...)
                  {
                      case FIRST:
                          ...
                          [[fallthrough]]
                      case SECOND:
                          ...
                  }
                  

                  This is correct code per C++17, C++ attribute: fallthrough (since C++17). It compiles with all warnings on. Creator red-underlines this with tooltip expected token ';' got '["``. Changing to [[gnu::fallthrough]] or [[clang::fallthrough]] does not help.

                  Shouldn't Creator's internal code model at least accept [[fallthrough]] which I think is just C++ 17 without special extensions? Should I report this? How do you annotate your case-fallthroughs? Maybe you use clang code model, does something work there?

                  S Offline
                  S Offline
                  SimonSchroeder
                  wrote on 9 Sept 2024, 08:03 last edited by
                  #7

                  @JonB said in Qt Creator Code Model error on legal attribute:

                  This is correct code per C++17, C++ attribute: fallthrough (since C++17).

                  As per the link you have provided yourself:

                  May only be applied to a null statement to create a fallthrough statement ([[fallthrough]];).

                  The semicolon is required per the standard. It is annoying, but it is what it is...

                  J 1 Reply Last reply 9 Sept 2024, 08:42
                  0
                  • J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on 9 Sept 2024, 08:21 last edited by
                    #8

                    there's always Q_FALLTHROUGH should work with old and new code model.


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    J 1 Reply Last reply 9 Sept 2024, 08:59
                    0
                    • S SimonSchroeder
                      9 Sept 2024, 08:03

                      @JonB said in Qt Creator Code Model error on legal attribute:

                      This is correct code per C++17, C++ attribute: fallthrough (since C++17).

                      As per the link you have provided yourself:

                      May only be applied to a null statement to create a fallthrough statement ([[fallthrough]];).

                      The semicolon is required per the standard. It is annoying, but it is what it is...

                      J Offline
                      J Offline
                      JonB
                      wrote on 9 Sept 2024, 08:42 last edited by
                      #9

                      @SimonSchroeder
                      Hi Simon. My bad example, I did read about the trailing ; and I did always have it there in all cases. I have edited my earlier code to include that now.

                      If you read the tooltip message I typed carefully it is clear the code model is actually expecting an end of statement ; prior to the closing ] not after it.

                      So that is not the issue. None of [[fallthrough]];, [[gnu::fallthrough]]; or [[clang::fallthrough]]; avoid the code editor red-underlining it with that error message. With gcc compiler the first two compile acceptably without warning, but the third one does not. Sadly/unexpectedly when I temporarily force Creator to use clangd despite memory warnings it makes no difference, all three get red-underlines with same message.

                      The only thing which keeps Creator happy and compiles without warning is @aha_1980's // fall through comment (for which thanks).

                      Could you please state what you use in C++ code for a case fall through?

                      Now that I have tried this with clang code model this is not right. At minimum [[fallthrough]]; is apparently standard C++ 17 so ISTM the editor should not incorrectly complain about. @aha_1980 said the internal code model is too old, but I don;t see why I should still get this with clangd code model. If I don't hear better here I shall be raising a bug report for this.

                      1 Reply Last reply
                      0
                      • J.HilkJ J.Hilk
                        9 Sept 2024, 08:21

                        there's always Q_FALLTHROUGH should work with old and new code model.

                        J Offline
                        J Offline
                        JonB
                        wrote on 9 Sept 2024, 08:59 last edited by
                        #10

                        @J-Hilk said in Qt Creator Code Model error on legal attribute:

                        there's always Q_FALLTHROUGH should work with old and new code model.

                        Nope. Q_FALLTHROUGH(); gets through the compiler fine without warning about fall through but Creator editor red-underlines the following case label. Replacing it with its gcc expansion, __attribute__((fallthrough)), red-underlines that statement.

                        Hmm, curiouser and curiouser. Q_FALLTHROUGH(); sometimes works in editor and sometimes not: Two screenshots:

                        1. b8b0d3f3-ef2f-4eaa-a2c5-8c2c8709d937-image.png

                        2. 336ef9bb-dbdc-4e00-a413-8ed73de0d525-image.png

                        In #1 you can see the red-underline, with tooltip about expected token ';'. By chance in #2 I happened to insert a blank line between the Q_FALLTHROUGH(); and the following case label. Lo and behold, the red underlining/complain tooltip gets removed. This is bizarre.....

                        So I am finding it pretty hard to know what works/does not work with C++ 17 and with/without clangd code model. Having code which includes a fall-through case statement is not that unusual, surely some of you have it? I am waiting/hoping to hear what you guys actually use in practice in your code, please...?

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          JonB
                          wrote on 9 Sept 2024, 09:26 last edited by JonB 9 Sept 2024, 09:43
                          #11

                          UPDATE/CORRECTION

                          I tried again with switching Use clangd on and off. Somehow it seems it didn't "take" right formerly. Now I do see different behaviour. I find that sometimes when I start Creator, it warns me I have don't have enough memory for clangd, I selected "Enable anyway", it still red-underlines [[fallthrough]];. Then I go to Preferences, switch off clangd and then switch it back on, that clears the complaint. It seems I have to switch off and back on every time to make it work. Sigh....

                          With clangd switched on I can use any of the [[fallthrough]]; annotations which get through gcc compiler and code editor does not red underline them. Q_FALLTHROUGH() macro still requires a blank line without clangd, but works without blank line with clangd. Fair enough, @aha_1980 has warned me that it will be "problematic* with the internal code model rather than clangd.

                          So all in all I can now use [[fallthrough]]; in my code with clangd, that is apparently "standard" C++ 17 so I accept that.

                          1 Reply Last reply
                          0
                          • J JonB has marked this topic as solved on 11 Sept 2024, 14:21

                          1/11

                          7 Sept 2024, 12:12

                          • Login

                          • Login or register to search.
                          1 out of 11
                          • First post
                            1/11
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved