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
Forum Updated to NodeBB v4.3 + New Features

/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 2 Watching
  • 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
    Driftwood
    wrote on 24 Aug 2020, 00:53 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?

    J 1 Reply Last reply 24 Aug 2020, 01:13
    0
    • D Driftwood
      24 Aug 2020, 00:53

      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?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 24 Aug 2020, 01:13 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

      D 1 Reply Last reply 24 Aug 2020, 01:34
      4
      • J JKSH
        24 Aug 2020, 01:13

        @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)

        D Offline
        D Offline
        Driftwood
        wrote on 24 Aug 2020, 01:34 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
        • K Offline
          K Offline
          Kent-Dorfman
          wrote on 24 Aug 2020, 04:01 last edited by
          #4

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

          J J J 4 Replies Last reply 24 Aug 2020, 05:37
          1
          • K Kent-Dorfman
            24 Aug 2020, 04:01

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

            J Offline
            J Offline
            JKSH
            Moderators
            wrote on 24 Aug 2020, 05:37 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
            • K Kent-Dorfman
              24 Aug 2020, 04:01

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

              J Offline
              J Offline
              JonB
              wrote on 24 Aug 2020, 08:46 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
              • K Kent-Dorfman
                24 Aug 2020, 04:01

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

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 24 Aug 2020, 08:50 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.

                K 1 Reply Last reply 25 Aug 2020, 04:11
                0
                • J J.Hilk
                  24 Aug 2020, 08:50

                  @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

                  K Offline
                  K Offline
                  Kent-Dorfman
                  wrote on 25 Aug 2020, 04:11 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
                  • K Kent-Dorfman
                    24 Aug 2020, 04:01

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

                    J Offline
                    J Offline
                    JKSH
                    Moderators
                    wrote on 26 Aug 2020, 14:05 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

                    D 1 Reply Last reply 27 Aug 2020, 12:47
                    4
                    • J JKSH
                      26 Aug 2020, 14:05

                      @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."

                      D Offline
                      D Offline
                      Driftwood
                      wrote on 27 Aug 2020, 12:47 last edited by
                      #10

                      @JKSH Thanks for the insight and link.

                      1 Reply Last reply
                      0

                      4/10

                      24 Aug 2020, 04:01

                      • Login

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