aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2012-04-16 22:29:51 -0400
committerJason Merrill <jason@gcc.gnu.org>2012-04-16 22:29:51 -0400
commit1561ad74c15ddf9c3d24e826ff280f5fa1d00ae2 (patch)
tree4990fd45ccbd69512a85642e2703881236066217
parent54aa834f49ab0e8855400d7d9ed513bf666ecb24 (diff)
downloadgcc-1561ad74c15ddf9c3d24e826ff280f5fa1d00ae2.zip
gcc-1561ad74c15ddf9c3d24e826ff280f5fa1d00ae2.tar.gz
gcc-1561ad74c15ddf9c3d24e826ff280f5fa1d00ae2.tar.bz2
re PR c++/38543 ([C++0x] Cannot specialize variadic template function)
PR c++/38543 * pt.c (determine_specialization): Instead of comparing the number of parms, check that tsubst gives the right answer. From-SVN: r186522
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/pt.c19
-rw-r--r--gcc/testsuite/ChangeLog3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/variadic131.C11
4 files changed, 28 insertions, 9 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 1b7f4be..8746c64 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2012-04-16 Jason Merrill <jason@redhat.com>
+ PR c++/38543
+ * pt.c (determine_specialization): Instead of comparing the number
+ of parms, check that tsubst gives the right answer.
+
PR c++/52008
* pt.c (process_partial_specialization): Complain about a partial
specialization with fewer args than primary template parms.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d6144d5..0ca6993 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1839,6 +1839,7 @@ determine_specialization (tree template_id,
{
tree decl_arg_types;
tree fn_arg_types;
+ tree insttype;
/* In case of explicit specialization, we need to check if
the number of template headers appearing in the specialization
@@ -1900,15 +1901,6 @@ determine_specialization (tree template_id,
fn_arg_types
= skip_artificial_parms_for (fn, fn_arg_types);
- /* Check that the number of function parameters matches.
- For example,
- template <class T> void f(int i = 0);
- template <> void f<int>();
- The specialization f<int> is invalid but is not caught
- by get_bindings below. */
- if (list_length (fn_arg_types) != list_length (decl_arg_types))
- continue;
-
/* Function templates cannot be specializations; there are
no partial specializations of functions. Therefore, if
the type of DECL does not match FN, there is no
@@ -1929,6 +1921,15 @@ determine_specialization (tree template_id,
specialize TMPL will produce DECL. */
continue;
+ /* Make sure that the deduced arguments actually work. */
+ insttype = tsubst (TREE_TYPE (fn), targs, tf_none, NULL_TREE);
+ if (insttype == error_mark_node)
+ continue;
+ fn_arg_types
+ = skip_artificial_parms_for (fn, TYPE_ARG_TYPES (insttype));
+ if (!compparms (fn_arg_types, decl_arg_types))
+ continue;
+
/* Save this template, and the arguments deduced. */
templates = tree_cons (targs, fn, templates);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2acdffe..0b6fcf5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
2012-04-16 Jason Merrill <jason@redhat.com>
+ PR c++/38543
+ * g++.dg/cpp0x/variadic131.C: New.
+
PR c++/52008
* g++.dg/cpp0x/variadic130.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/variadic131.C b/gcc/testsuite/g++.dg/cpp0x/variadic131.C
new file mode 100644
index 0000000..3006f87
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/variadic131.C
@@ -0,0 +1,11 @@
+// PR c++/38543
+// { dg-do compile { target c++11 } }
+
+template< typename ... T > void foo( T ... args );
+template<> void foo( ){}
+template<> void foo(int,double){}
+int main()
+{
+ foo( 0, 0.0 );
+ return 55;
+}