This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/83249] New: C++11 Parameter pack deduced incorrectly in decltype return declaration


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83249

            Bug ID: 83249
           Summary: C++11 Parameter pack deduced incorrectly in decltype
                    return declaration
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: russ at yanofsky dot org
  Target Milestone: ---

Following code fails to compile with gcc 7.2.0 and versions back to 5.4.0. It
does successfully compile with clang.

What appears to happen is that arguments to S::g(P1... p1, P2... p2)
incorrectly become part of the "p1" parameter pack instead of "p2" parameter
pack. This only seems to happen when p1 is referenced inside a decltype return
type declaration. When "p1" and "p2" are referenced inside the actual function
body they are assigned correctly.

////////////////////////////////////////////////////////////////////
void f();

template <typename... P1>
struct S
{
    template <typename... P2>
    auto g(P1... p1, P2... p2) -> decltype(f(p1...));
};

void test() {
    S<>().g(1, 2);
}
////////////////////////////////////////////////////////////////////

Command line and error output:

g++ -c -std=c++11 main.cpp
<source>: In function 'void test()':
11 : <source>:11:17: error: no matching function for call to 'S<>::g(int, int)'
     S<>().g(1, 2);
                 ^
7 : <source>:7:10: note: candidate: template<class ... P2> decltype (f(S::g::p1
...)) S<P1>::g(P1 ..., P2 ...) [with P2 = {P2 ...}; P1 = {}]
     auto g(P1... p1, P2... p2) -> decltype(f(p1...));
          ^
7 : <source>:7:10: note:   template argument deduction/substitution failed:
<source>: In substitution of 'template<class ... P2> decltype (f(S::g::p2 ...))
S<>::g<P2 ...>(P2 ...) [with P2 = {int, int}]':
11 : <source>:11:17:   required from here
7 : <source>:7:45: error: too many arguments to function 'void f()'
     auto g(P1... p1, P2... p2) -> decltype(f(p1...));
                                            ~^~~~~~~
1 : <source>:1:6: note: declared here
 void f();
      ^
Compiler exited with result code 1

////////////////////////////////////////////////////////////////////

Tested with:

g++ (GCC-Explorer-Build) 7.2.0 https://godbolt.org/g/ma8oNz
g++ (Gentoo Hardened 6.4.0 p1.1) 6.4.0
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04) 6.3.0 20170519

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]