Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. /test/main.cpp:3: error: 'auto' not allowed in function prototype
QtWS25 Last Chance

/test/main.cpp:3: error: 'auto' not allowed in function prototype

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 1.8k 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.
  • DriftwoodD Offline
    DriftwoodD Offline
    Driftwood
    wrote on last edited by
    #1

    I'm using gcc 9.3.0 and have no issues running this code in Code::Blocks IDE or the CLion IDE.

    #include <iostream>
    
    void addAndPrint(auto x, auto y) // only valid starting in C++20
    {
        std::cout << x + y << '\n';
    }
    
    int main()
    {
        addAndPrint(2, 3); // int
        addAndPrint(4.5, 6.7); // double
    }
    

    But Qt Creator 4.12.0 complains about it,

    alt text
    although the code compiles and runs fine. What exactly's going on here?

    JKSHJ 1 Reply Last reply
    0
    • DriftwoodD Driftwood

      I'm using gcc 9.3.0 and have no issues running this code in Code::Blocks IDE or the CLion IDE.

      #include <iostream>
      
      void addAndPrint(auto x, auto y) // only valid starting in C++20
      {
          std::cout << x + y << '\n';
      }
      
      int main()
      {
          addAndPrint(2, 3); // int
          addAndPrint(4.5, 6.7); // double
      }
      

      But Qt Creator 4.12.0 complains about it,

      alt text
      although the code compiles and runs fine. What exactly's going on here?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Driftwood said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

      But Qt Creator 4.12.0 complains about it....

      although the code compiles and runs fine. What exactly's going on here?

      The inline warnings/errors are generated by the Clang Code Model (see https://doc.qt.io/qtcreator/creator-clang-codemodel.html ) This model performs live code analysis separately from your compiler.

      According to the documentation, the code model currently supports up to C++17. You can disable the model if you wish (see the link for instructions)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      DriftwoodD 1 Reply Last reply
      4
      • JKSHJ JKSH

        @Driftwood said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

        But Qt Creator 4.12.0 complains about it....

        although the code compiles and runs fine. What exactly's going on here?

        The inline warnings/errors are generated by the Clang Code Model (see https://doc.qt.io/qtcreator/creator-clang-codemodel.html ) This model performs live code analysis separately from your compiler.

        According to the documentation, the code model currently supports up to C++17. You can disable the model if you wish (see the link for instructions)

        DriftwoodD Offline
        DriftwoodD Offline
        Driftwood
        wrote on last edited by
        #3

        @JKSH Thanks for clearing that up. It isn't a big deal, so I'll leave it as it. I'm sure C++20 support is right around the corner.

        1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

          JKSHJ JonBJ J.HilkJ 4 Replies Last reply
          1
          • Kent-DorfmanK Kent-Dorfman

            but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            @Kent-Dorfman said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

            but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

            Kindly start your wars at a safe distance from this community. Thank you. 😉

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            5
            • Kent-DorfmanK Kent-Dorfman

              but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Kent-Dorfman said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

              but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

              Time to abandon C++ and just use Python... :(

              1 Reply Last reply
              0
              • Kent-DorfmanK Kent-Dorfman

                but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Kent-Dorfman with the probability to start I wildefire, I have to disagree.
                It's much more readable/understandable then the template version.
                Not necessarily on the OP's case ( for a simple cout) but in general


                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.

                Kent-DorfmanK 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Kent-Dorfman with the probability to start I wildefire, I have to disagree.
                  It's much more readable/understandable then the template version.
                  Not necessarily on the OP's case ( for a simple cout) but in general

                  Kent-DorfmanK Offline
                  Kent-DorfmanK Offline
                  Kent-Dorfman
                  wrote on last edited by
                  #8

                  @J-Hilk It's new and it's cool, but it's dangerous, as it encourages implicit type conversions, which are themselves dangerous. I'll stick with templates, and explicitly cast hex on those who disagree. LOL

                  1 Reply Last reply
                  0
                  • Kent-DorfmanK Kent-Dorfman

                    but to risk a flame war, supporting that kind of c++20 function prototyping is an abomination!

                    JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    @Driftwood said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

                    I'm sure C++20 support is right around the corner.

                    And you're absolutely right!

                    https://www.qt.io/blog/qt-creator-4.13-released -- "We updated LLVM for the C++ code model to LLVM 10, implicitly improving support for C++20 features."

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    DriftwoodD 1 Reply Last reply
                    4
                    • JKSHJ JKSH

                      @Driftwood said in /test/main.cpp:3: error: 'auto' not allowed in function prototype:

                      I'm sure C++20 support is right around the corner.

                      And you're absolutely right!

                      https://www.qt.io/blog/qt-creator-4.13-released -- "We updated LLVM for the C++ code model to LLVM 10, implicitly improving support for C++20 features."

                      DriftwoodD Offline
                      DriftwoodD Offline
                      Driftwood
                      wrote on last edited by
                      #10

                      @JKSH Thanks for the insight and link.

                      1 Reply Last reply
                      0

                      • Login

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