OSDN Git Service

cp:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Oct 2005 11:19:12 +0000 (11:19 +0000)
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 17 Oct 2005 11:19:12 +0000 (11:19 +0000)
PR c++/21353
* g++.dg/template/defarg6.C: New.
testsuite:
PR c++/21353
* decl.c (check_default_argument): Don't check
processing_template_decl or uses_template_parms here.
(grokparms): Only call check_default_argument when not processing
a template decl.
* parser.c (cp_parser_late_parsing_default_arg): Call
check_default_argument when not processing a template decl.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@105492 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/defarg6.C [new file with mode: 0644]

index 9305e16..a725969 100644 (file)
@@ -1,3 +1,13 @@
+2005-10-17  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/21353
+       * decl.c (check_default_argument): Don't check
+       processing_template_decl or uses_template_parms here.
+       (grokparms): Only call check_default_argument when not processing
+       a template decl.
+       * parser.c (cp_parser_late_parsing_default_arg): Call
+       check_default_argument when not processing a template decl.
+
 2005-10-16  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/24389
index eafebc1..982fe12 100644 (file)
@@ -8453,13 +8453,6 @@ check_default_argument (tree decl, tree arg)
        deal with it after the class is complete.  */
     return arg;
 
-  if (processing_template_decl || uses_template_parms (arg))
-    /* We don't do anything checking until instantiation-time.  Note
-       that there may be uninstantiated arguments even for an
-       instantiated function, since default arguments are not
-       instantiated until they are needed.  */
-    return arg;
-
   if (TYPE_P (decl))
     {
       decl_type = decl;
@@ -8601,10 +8594,10 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms)
                       decl, ptr ? "pointer" : "reference", t);
            }
 
-         if (!any_error && init)
-           init = check_default_argument (decl, init);
-         else
+         if (any_error)
            init = NULL_TREE;
+         else if (init && !processing_template_decl)
+           init = check_default_argument (decl, init);
        }
 
       TREE_CHAIN (decl) = decls;
index 7f27943..45fc69f 100644 (file)
@@ -15654,6 +15654,9 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn)
       /* Parse the assignment-expression.  */
       parsed_arg = cp_parser_assignment_expression (parser, /*cast_p=*/false);
 
+      if (!processing_template_decl)
+       parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg);
+      
       TREE_PURPOSE (parm) = parsed_arg;
 
       /* Update any instantiations we've already created.  */
index 701122a..6eeadc5 100644 (file)
@@ -1,3 +1,8 @@
+2005-10-17  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/21353
+       * g++.dg/template/defarg6.C: New.
+
 2005-10-17  Uros Bizjak  <uros@kss-loka.si>
 
        PR target/24315
diff --git a/gcc/testsuite/g++.dg/template/defarg6.C b/gcc/testsuite/g++.dg/template/defarg6.C
new file mode 100644 (file)
index 0000000..f4d8468
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright (C) 2005 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 14 Oct 2005 <nathan@codesourcery.com>
+
+// PR 21353 missing error.
+// Origin:Andrew Pinski <pinskia@gcc.gnu.org>
+
+enum X{ a, b, c };
+
+struct C
+{
+  static void func (X &ref = a); // { dg-error "default argument" "" }
+};
+
+template <typename T>
+struct D
+{
+  static void func (X &ref = a); // not an error at this point
+};
+
+void Foo (X & obj)
+{
+  D<int>::func (obj);
+
+  D<int>::func (); // { dg-error "default argument" "" }
+}