Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86093

when can we use “auto” in function prototype?

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Closed
    • Priority: Not Evaluated
    • Resolution: Invalid
    • Affects Version/s: 5.14.2
    • Fix Version/s: None
    • Component/s: Build System
    • Labels:
      None
    • Platform/s:
      Windows

      Description

      when I use  auto in function parameter,there always is an error: 'auto' not allowed in function prototype.

       

      #include <iostream>
      #include <deque>
      #include <list>
      #include <vector>
      #include <functional>
      
      static auto consumer(auto& container) {
          return [&](auto val) {container.push_back(val); };
      }
      
      static void print(const auto& container) {
          for (auto i : container) {
              std::cout << i << ",";
          }
          std::cout << std::endl;
      }
      
      int main()
      {
          std::list<int> l;
          std::vector<int> v;
          std::deque<int> d;
      
          const std::vector<std::function<void(int)>>consumers{ consumer(l),consumer(v),consumer(d) };
          for (int i = 0; i < 10; ++i) {
              for (auto &&consumer : consumers) {
                  consumer(i);
              }
          }
          print(l);
          print(v);
          print(d);
          return 0;
      }
      

      there will be errors in line 7 and line 11 in QT Creator.

      config = c17 or c+2a, it can't run.

      But it can run propreately with nothing.

       

      Qt version: 5.15.0 MinGW 64-bit

      complier: MinGW  8.1.0  64-bit

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            qtbuildsystem Qt Build System Team
            Reporter:
            peior peior wu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes