Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator - Clang Code Model with GNU code

Qt Creator - Clang Code Model with GNU code

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 509 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.
  • D Offline
    D Offline
    dawnwhite
    wrote on 22 Jan 2022, 21:26 last edited by
    #1

    How can I tell the Code Model to use '-std=gnu11' ?
    So that it wouldn't flag things like nested functions as "error: function definition is not allowed here".

    When I try to add it as "Diagnostic Configuration" I get told: 'Option "-std=gnu11" is invalid.'
    Is this a limitation from libclang, or is the Option-validation-checker too strict?

    Thanks

    K 1 Reply Last reply 24 Jan 2022, 00:12
    0
    • D dawnwhite
      22 Jan 2022, 21:26

      How can I tell the Code Model to use '-std=gnu11' ?
      So that it wouldn't flag things like nested functions as "error: function definition is not allowed here".

      When I try to add it as "Diagnostic Configuration" I get told: 'Option "-std=gnu11" is invalid.'
      Is this a limitation from libclang, or is the Option-validation-checker too strict?

      Thanks

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 24 Jan 2022, 00:12 last edited by kshegunov
      #2

      @dawnwhite said in Qt Creator - Clang Code Model with GNU code:

      So that it wouldn't flag things like nested functions as "error: function definition is not allowed here".

      Well, this is not standard C++, so don't do it to begin with. Use an anonymous struct/class instead:

      void function()
      {
          struct {
             void operator () (int a)
             {
             }
          } nested;
          
          int b = 0;
          nested(b);
      }
      

      Or simply use a lambda.

      When I try to add it as "Diagnostic Configuration" I get told: 'Option "-std=gnu11" is invalid.'
      Is this a limitation from libclang, or is the Option-validation-checker too strict?

      I don't believe libclang supports gnu extensions.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3
      • D Offline
        D Offline
        dawnwhite
        wrote on 24 Jan 2022, 19:13 last edited by dawnwhite
        #3

        Thank your for your response!

        so don't do it to begin with.

        I work with an large existing code base, so this is not an option. Think of the linux kernel for example.

        I was able to set -std=gnu11 by editing ~/.config/QtProject/QtCreator.ini manually, and now many gcc extensions are supported.
        It would be great if this was supported by the gui somehow. A quick hack would be to whitelist -std=* in isValidOption.

        I don't believe libclang supports gnu extensions.

        While nested functions indeed seem to be unsupported, many GNU extensions are supported! From LanguageExtensions.html: Clang aims to support a broad range of GCC extensions.

        K 1 Reply Last reply 24 Jan 2022, 19:33
        0
        • D dawnwhite
          24 Jan 2022, 19:13

          Thank your for your response!

          so don't do it to begin with.

          I work with an large existing code base, so this is not an option. Think of the linux kernel for example.

          I was able to set -std=gnu11 by editing ~/.config/QtProject/QtCreator.ini manually, and now many gcc extensions are supported.
          It would be great if this was supported by the gui somehow. A quick hack would be to whitelist -std=* in isValidOption.

          I don't believe libclang supports gnu extensions.

          While nested functions indeed seem to be unsupported, many GNU extensions are supported! From LanguageExtensions.html: Clang aims to support a broad range of GCC extensions.

          K Offline
          K Offline
          kshegunov
          Moderators
          wrote on 24 Jan 2022, 19:33 last edited by
          #4

          @dawnwhite said in Qt Creator - Clang Code Model with GNU code:

          I work with an large existing code base, so this is not an option. Think of the linux kernel for example.

          Think refactoring. I sure hope the kernel doesn't require extensions to the C language just to compile.

          I was able to set -std=gnu11 by editing ~/.config/QtProject/QtCreator.ini manually, and now many gcc extensions are supported.

          Thanks for sharing!

          While nested functions indeed seem to be unsupported, many GNU extensions are supported! From LanguageExtensions.html: Clang aims to support a broad range of GCC extensions.

          Well, yeah, I mean in the general sense of "all" gnu extensions. People try to play nice, and personally I like to use the gcc attributes with clang as well.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          1/4

          22 Jan 2022, 21:26

          • Login

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