Bug 52380 - [C++11] Number of variadic template arguments wrongly interpreted in class template
Summary: [C++11] Number of variadic template arguments wrongly interpreted in class te...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.1
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2012-02-25 11:26 UTC by Ai Azuma
Modified: 2012-04-16 03:53 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-04-16 00:00:00


Attachments
Output of -v option and preprocessed file (1.20 KB, text/plain)
2012-02-25 11:26 UTC, Ai Azuma
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ai Azuma 2012-02-25 11:26:30 UTC
Created attachment 26752 [details]
Output of -v option and preprocessed file

Here is a reproducer;

///////////////////////////////////////////////
// An enclosing class template is necessary to
// reproduce the bug.
template<typename T>
struct S
{
  template<typename U>
  struct Unary                        // Line 5
  {};

  template<unsigned, typename... Args>
  struct Dispatch                     // Line 9
    : public Unary<Args...>
  {};

  template<typename... Args>
  struct Variadic
    : public Dispatch<sizeof...(Args), Args...>
  {};
};

int main()
{
  S<void>::Variadic<void> z;
}
///////////////////////////////////////////////

GCC 4.7.0 20120218 (experimental) with -std=c++11 complains about the above code;

main.cpp: In instantiation of 'struct S<void>::Dispatch<1u, void>':
main.cpp:14:10:   required from 'struct S<void>::Variadic<void>'
main.cpp:21:27:   required from here
main.cpp:9:10: error: wrong number of template arguments (2, should be 1)
main.cpp:5:10: error: provided for 'template<class T> template<class U> struct S<T>::Unary'

Obviously, just one template argument is passed to `Unary'. However, GCC misinterprets the number of template arguments as two.
Comment 1 Jason Merrill 2012-04-16 03:18:13 UTC
Author: jason
Date: Mon Apr 16 03:18:06 2012
New Revision: 186479

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186479
Log:
	PR c++/52292
	PR c++/52380
	* pt.c (coerce_template_parms): Even if we aren't converting we
	want to expand argument packs.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic124.C
    trunk/gcc/testsuite/g++.dg/cpp0x/variadic125.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2012-04-16 03:40:38 UTC
Author: jason
Date: Mon Apr 16 03:40:34 2012
New Revision: 186481

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186481
Log:
	PR c++/52292
	PR c++/52380
	* pt.c (coerce_template_parms): Even if we aren't converting we
	want to expand argument packs.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/variadic124.C
    branches/gcc-4_7-branch/gcc/testsuite/g++.dg/cpp0x/variadic125.C
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/pt.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2012-04-16 03:53:12 UTC
Fixed for 4.7.1.