]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/28274 (Redeclaration with extra default argument doesn't work)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Thu, 3 Aug 2006 02:41:33 +0000 (02:41 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Thu, 3 Aug 2006 02:41:33 +0000 (02:41 +0000)
PR c++/28274
* decl.c (duplicate_decls): Call check_default_args here.
(start_preparsed_function): Do not call check_default_args.
* name-lookup.c (pushdecl_maybe_friend): Only call
check_default_args if duplicate_decls got bypassed.

* g++.dg/other/default5.C: New test.

From-SVN: r115895

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/default5.C [new file with mode: 0644]

index 9cc14806724d13c57fdcb3ed93799c7966d6f07f..29c59982fc8478e3d09d37923fbcce717f7ccd0c 100644 (file)
@@ -1,3 +1,11 @@
+2006-08-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/28274
+       * decl.c (duplicate_decls): Call check_default_args here.
+       (start_preparsed_function): Do not call check_default_args.
+       * name-lookup.c (pushdecl_maybe_friend): Only call
+       check_default_args if duplicate_decls got bypassed.
+
 2006-07-24  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/27572
index a9d82142ffd583ad93966b1e5c0f409bc89bff22..63b491c684b57754c552c57c21897ea22115fe2a 100644 (file)
@@ -1573,6 +1573,9 @@ duplicate_decls (tree newdecl, tree olddecl)
        }
       TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
 
+      if (TREE_CODE (newdecl) == FUNCTION_DECL)
+       check_default_args (newdecl);
+
       /* Lay the type out, unless already done.  */
       if (! same_type_p (newtype, oldtype)
          && TREE_TYPE (newdecl) != error_mark_node
@@ -10009,8 +10012,6 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
      you declare a function, these types can be incomplete, but they
      must be complete when you define the function.  */
   check_function_type (decl1, current_function_parms);
-  /* Make sure no default arg is missing.  */
-  check_default_args (decl1);
 
   /* Build the return declaration for the function.  */
   restype = TREE_TYPE (fntype);
index 2f1d39ec5c09f049adc4acf1bcf4632ec126486e..8491444120690a963ed966936996c920e754bd4e 100644 (file)
@@ -601,9 +601,6 @@ pushdecl (tree x)
     {
       int different_binding_level = 0;
 
-      if (TREE_CODE (x) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (x))
-       check_default_args (x);
-
       if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
        name = TREE_OPERAND (name, 0);
 
@@ -732,6 +729,9 @@ pushdecl (tree x)
            }
        }
 
+      if (TREE_CODE (x) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (x))
+       check_default_args (x);
+
       check_template_shadow (x);
 
       /* If this is a function conjured up by the backend, massage it
index 9a809b68009aa640bceddcf86913c816c045e39b..e5c63259365628ad3694a1029af28f8fe6d6edd7 100644 (file)
@@ -1,3 +1,8 @@
+2006-08-03  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/28274
+       * g++.dg/other/default5.C: New test.
+
 2006-07-30  Roger Sayle  <roger@eyesopen.com>
 
        PR middle-end/28473
diff --git a/gcc/testsuite/g++.dg/other/default5.C b/gcc/testsuite/g++.dg/other/default5.C
new file mode 100644 (file)
index 0000000..ad7eb01
--- /dev/null
@@ -0,0 +1,47 @@
+// PR c++/28274
+// { dg-do "compile" }
+
+void f1(int, int, int, int, int = 0);
+void f1(int, int, int, int = 0, int);
+void f1(int, int, int = 0, int, int);
+void f1(int = 0, int, int, int, int);    // { dg-error "default" }
+
+void f2(int, int, int, int, int = 0) {}
+void f2(int, int, int, int = 0, int);
+void f2(int, int, int = 0, int, int);
+void f2(int = 0, int, int, int, int);    // { dg-error "default" }
+
+void f3(int, int, int, int, int = 0);
+void f3(int, int, int, int = 0, int) {}
+void f3(int, int, int = 0, int, int);
+void f3(int = 0, int, int, int, int);    // { dg-error "default" }
+
+void f4(int, int, int, int, int = 0);
+void f4(int, int, int, int = 0, int);
+void f4(int, int, int = 0, int, int) {}
+void f4(int = 0, int, int, int, int);    // { dg-error "default" }
+
+void f5(int, int, int, int, int = 0);
+void f5(int, int, int, int = 0, int);
+void f5(int, int, int = 0, int, int);
+void f5(int = 0, int, int, int, int) {}  // { dg-error "default" }
+
+
+struct A
+{
+  void F1(int, int, int = 0);
+  void F2(int, int, int = 0);
+};
+
+void A::F1(int, int = 0, int) {}
+void A::F2(int = 0, int, int) {}  // { dg-error "default" }
+
+
+template<int> struct B
+{
+  void F1(int, int, int = 0);
+  void F2(int, int, int = 0);
+};
+
+template<int N> void B<N>::F1(int, int = 0, int) {}
+template<int N> void B<N>::F2(int = 0, int, int) {}  // { dg-error "default" }