[C++0x PATCH] Extending variadic template template parameters (N2488)

Doug Gregor doug.gregor@gmail.com
Sat Dec 15 10:10:00 GMT 2007

This patch, to be applied on top of my fixes for template template
parameters (http://gcc.gnu.org/ml/gcc-patches/2007-12/msg00709.html),
implements the extension to variadic template template parameters
described in N2488, available here:


The extension is a simple one, relaxing the restrictions on which
template template parameters can bind to which template arguments when
the template template parameter's template parameter list contains a
parameter pack. Read the paper for the details; the implementation
itself is very straightforward, and the patch only looks non-trivial
because I separated out the loop body from
coerce_template_template_parms into its own function

This is one of those patches that pushes on the rules a bit. There are
obvious reasons not to accept it: we're in stage 3, so we shouldn't be
changing anything that isn't a bug fix. The extension in question
hasn't yet been accepted into C++0x (it will be discussed in Bellevue
this February), so it could be viewed as a GNU extension (if one is
being pedantic).

That said, rejecting this patch is absolutely the wrong thing to do :)

>From the perspective of C++0x, it's bad to have a feature implemented
in a released compiler that is known to have different semantics than
what we expect in C++0x. People trying out the feature will
misunderstand the details of the feature, misinformation will be
distributed, rebuked, reiterated, etc. Yes, features will evolve, and
inevitably we'll ship a C++0x feature with the wrong semantics. But
there's a difference between knowingly shipping a wrong compiler and
accidentally shipping a wrong compiler; we know this is coming, and
it's easy to deal with now.

So, putting this into mainline now puts us a little ahead of the
curve, because it hasn't been accepted yet. However, wording for this
small extension is available (see N2488), the extension itself is
strongly motivated by actual use cases (again, see N2488) and
extensively tested with those same use cases, and there has been a
significant amount of support for this extension already (with no
disagreements about it, at least thus far). Given these factors, I
would be shocked---shocked!---if it did not go into C++0x this
February at the Bellevue meeting. Remember: variadic templates
themselves went through the C++ committee in a single meeting. It
would be a shame if the entire GCC 4.3 series missed out on this
change (thereby hobbling C++0x-enabled libraries like the updated
Boost.MPL and Proto) by a few weeks.

Tested i686-pc-linux-gnu.

  - Doug

2007-12-15  Douglas Gregor  <doug.gregor@gmail.com>

	* pt.c (coerce_template_template_parm): Moved the body of the loop
	of coerce_template_template_parms here, to make iteration over a
	template argument pack simpler.
	Also, allow matching of a template parameter pack in the template
	template parameter to a template parameter in the template
	template argument.
	(coerce_template_template_parms): Deal with variadic template
	template parameters. Use coerce_template_template_parm.
	(unify): Make sure we coerce the template template argument's
	template arguments to the template template parameter's template
	parameters, not the other way around.

2007-12-15  Douglas Gregor  <doug.gregor@gmail.com>

	* g++.dg/cpp0x/variadic84.C: Update to reflect the change in
	variadic template template parameter binding semantics.
	* g++.dg/cpp0x/variadic85.C: Ditto.
	* g++.dg/cpp0x/variadic88.C: New.
	* g++.dg/cpp0x/variadic89.C: New.
	* g++.dg/cpp0x/variadic90.C: New.
	* g++.dg/cpp0x/variadic-ex14.C: Update to reflect the change in
	variadic template template parameter binding semantics.
	* g++.dg/cpp0x/variadic-lambda.C: New.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: n2488-cp.patch
Type: text/x-patch
Size: 7573 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071215/546621c5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: n2488-testsuite.patch
Type: text/x-patch
Size: 6469 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20071215/546621c5/attachment-0001.bin>

More information about the Gcc-patches mailing list