1 Reply Latest reply on Jun 18, 2018 8:45 AM by Maxim Kartashev-Oracle

    decltype(auto) does not work for template functions

    koval

      Studio 12.6 fails to compile the following code:

      int fun1(int x);
      
      template<typename T>
      decltype(auto) fun2(int x, T)
      {
          return fun1(x);
      }
      
      decltype(auto) fun3(int x, short s)
      {
          return fun2(x, s);
      }
      

       

      CC -c -std=c++14 decltype.cpp

      "decltype.cpp", line 11: Error: Could not find a match for fun2<T>(int, short) needed in fun3(int, short).

      1 Error(s) detected.

       

      When fun2's return type is changed to explicit int (or decltype(fun1(x))) the error disappears, even though fun3 still uses decltype(auto)