re PR c++/53856 (Default argument allowed on member defined outside of class template)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 5 Oct 2015 21:43:26 +0000 (21:43 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 5 Oct 2015 21:43:26 +0000 (21:43 +0000)
/cp
2015-10-05  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/53856
* pt.c (check_default_tmpl_args): Per [temp.param]/9, do not
reject default template arguments in out of class definitions
of members of non-template classes.

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

PR c++/53856
* g++.dg/template/defarg19.C: New.
* g++.dg/template/defarg20.C: Likewise.

From-SVN: r228501

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/defarg19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/defarg20.C [new file with mode: 0644]

index d4fd514..63ed047 100644 (file)
@@ -1,3 +1,10 @@
+2015-10-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/53856
+       * pt.c (check_default_tmpl_args): Per [temp.param]/9, do not
+       reject default template arguments in out of class definitions
+       of members of non-template classes.
+
 2015-10-05  Richard Sandiford  <richard.sandiford@arm.com>
 
        * tree.c (cp_tree_equal): Use real_equal instead of
index db947cc..6520b8b 100644 (file)
@@ -4940,8 +4940,15 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
   else if (is_partial)
     msg = G_("default template arguments may not be used in "
             "partial specializations");
-  else
+  else if (current_class_type && CLASSTYPE_IS_TEMPLATE (current_class_type))
     msg = G_("default argument for template parameter for class enclosing %qD");
+  else
+    /* Per [temp.param]/9, "A default template-argument shall not be
+       specified in the template-parameter-lists of the definition of
+       a member of a class template that appears outside of the member's
+       class.", thus if we aren't handling a member of a class template
+       there is no need to examine the parameters.  */
+    return true;
 
   if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
     /* If we're inside a class definition, there's no need to
index cbec9c9..3d268e7 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-05  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/53856
+       * g++.dg/template/defarg19.C: New.
+       * g++.dg/template/defarg20.C: Likewise.
+
 2015-10-05  Aditya Kumar  <aditya.k7@samsung.com>
            Sebastian Pop  <s.pop@samsung.com>
 
diff --git a/gcc/testsuite/g++.dg/template/defarg19.C b/gcc/testsuite/g++.dg/template/defarg19.C
new file mode 100644 (file)
index 0000000..8569802
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/53856
+
+template<typename T>
+struct A
+{
+  struct B;
+};
+
+template<typename T = int>
+struct A<T>::B  // { dg-error "default argument" }
+{
+  int i;
+};
+
+A<int>::B b = { };
diff --git a/gcc/testsuite/g++.dg/template/defarg20.C b/gcc/testsuite/g++.dg/template/defarg20.C
new file mode 100644 (file)
index 0000000..de8aac1
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/53856
+
+struct A
+{
+  template<typename T>
+  struct B;
+};
+
+template<typename T = int>
+struct A::B
+{
+  int i;
+};
+
+A::B<int> b = { };