[C++ Patch] PR 65370

Paolo Carlini paolo.carlini@oracle.com
Tue Mar 10 15:50:00 GMT 2015


Hi,

my fix for c++/15339 caused this regression, where we now reject the 
below valid testcase. I think we can handle the problem by adding an 
early return to check_redeclaration_no_default_args.

Tested x86_64-linux.

Thanks,
Paolo.

///////////////////////
-------------- next part --------------
/cp
2015-03-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65370
	* decl.c (check_redeclaration_no_default_args): Avoid spurious
	errors for member template functions of specialized class templates.

/testsuite
2015-03-10  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/65370
	* g++.dg/other/default11.C: New.
-------------- next part --------------
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 221317)
+++ cp/decl.c	(working copy)
@@ -1271,6 +1271,22 @@ check_redeclaration_no_default_args (tree decl)
 {
   gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
 
+  /* Don't get fooled by, eg:
+
+     template <typename> class C
+     {
+       template <typename U>
+       C(const C<U>&, bool = false);
+     };
+
+     template <>
+     template <typename U>
+     C<int>::C(const C<U>&, bool);  */
+
+  if (DECL_FUNCTION_MEMBER_P (decl)
+      && CLASSTYPE_SPECIALIZATION_OF_PRIMARY_TEMPLATE_P (DECL_CONTEXT (decl)))
+    return;
+
   for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
        t && t != void_list_node; t = TREE_CHAIN (t))
     if (TREE_PURPOSE (t))
Index: testsuite/g++.dg/other/default11.C
===================================================================
--- testsuite/g++.dg/other/default11.C	(revision 0)
+++ testsuite/g++.dg/other/default11.C	(working copy)
@@ -0,0 +1,11 @@
+// PR c++/65370
+
+template <typename> class C
+{
+  template <typename U>
+  C(const C<U>&, bool = false);
+};
+
+template <>
+template <typename U>
+C<int>::C(const C<U>&, bool);


More information about the Gcc-patches mailing list