Bug 28274 - [4.3 Regression] Redeclaration with extra default argument doesn't work
Summary: [4.3 Regression] Redeclaration with extra default argument doesn't work
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P2 normal
Target Milestone: 4.4.0
Assignee: Not yet assigned to anyone
URL:
Keywords: monitored, rejects-valid
: 29177 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-07-05 18:29 UTC by Jorn Wolfgang Rennecke
Modified: 2011-06-27 11:09 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.6, 3.4.0, 3.4.5, 4.0.0, 4.0.1, 4.0.2, 4.4.0
Known to fail: 3.4.6, 4.0.3, 4.1.0, 4.2.0, 4.3.0
Last reconfirmed: 2006-07-06 03:08:07


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-07-05 18:29:11 UTC
bash-2.05b$ cat defarg.C
int f (int i, int j = 0);
int f (int i = 0, int j);
bash-2.05b$ ./cc1plus defarg.C  -quiet
defarg.C:2: error: default argument missing for parameter 2 of ‘int f(int, int)’
defarg.C:2: error: default argument given for parameter 2 of ‘int f(int, int)’
defarg.C:1: error: after previous specification in ‘int f(int, int)’
Comment 1 Andrew Pinski 2006-07-06 03:08:07 UTC
Confirmed, at least a 4.1/4.2 regression, I cannot test 4.0.x but I do know that "4.1.0 20051026" worked and so did "4.0.0 20050225".
Comment 2 Volker Reichelt 2006-07-27 20:31:42 UTC
This was caused by my patch for PR 16829.
I'll take care of it.
Comment 3 patchapp@dberlin.org 2006-07-28 11:35:26 UTC
Subject: Bug number PR c++/28274

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-07/msg01189.html
Comment 4 Volker Reichelt 2006-08-03 02:30:59 UTC
Subject: Bug 28274

Author: reichelt
Date: Thu Aug  3 02:30:49 2006
New Revision: 115893

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115893
Log:
	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.

Added:
    trunk/gcc/testsuite/g++.dg/other/default5.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl.c
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog

Comment 5 Volker Reichelt 2006-08-03 02:34:22 UTC
Subject: Bug 28274

Author: reichelt
Date: Thu Aug  3 02:34:14 2006
New Revision: 115894

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115894
Log:
	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.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/g++.dg/other/default5.C
Modified:
    branches/gcc-4_1-branch/gcc/cp/ChangeLog
    branches/gcc-4_1-branch/gcc/cp/decl.c
    branches/gcc-4_1-branch/gcc/cp/name-lookup.c
    branches/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 6 Volker Reichelt 2006-08-03 02:41:41 UTC
Subject: Bug 28274

Author: reichelt
Date: Thu Aug  3 02:41:33 2006
New Revision: 115895

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115895
Log:
	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.

Added:
    branches/gcc-4_0-branch/gcc/testsuite/g++.dg/other/default5.C
Modified:
    branches/gcc-4_0-branch/gcc/cp/ChangeLog
    branches/gcc-4_0-branch/gcc/cp/decl.c
    branches/gcc-4_0-branch/gcc/cp/name-lookup.c
    branches/gcc-4_0-branch/gcc/testsuite/ChangeLog

Comment 7 Volker Reichelt 2006-08-03 03:10:06 UTC
Fixed on mainline, 4.1 branch, and 4.0 branch.
Comment 8 Andrew Pinski 2006-09-22 08:04:00 UTC
*** Bug 29177 has been marked as a duplicate of this bug. ***
Comment 9 Jason Merrill 2009-02-11 21:28:55 UTC
This is still broken inside extern "C":

extern "C" {
void foo (int i, int j = 6);
void foo (int i = 4, int j);
}
Comment 10 Jason Merrill 2009-02-11 21:31:08 UTC
The extern "C" testcase passed under the 3.2 compiler; marking as regression.
Comment 11 andreasmeier80 2009-02-25 10:33:05 UTC
The target milestone 4.0.4 is wrong 
Comment 12 Volker Reichelt 2009-02-25 21:00:12 UTC
The culprit is in the function pushdecl_maybe_friend:
Functions declared extern "C" bypass the usual mechanism, because
duplicate_decls isn't called for them (see lines 727ff):

	  else if ((DECL_EXTERN_C_FUNCTION_P (x)
		    || DECL_FUNCTION_TEMPLATE_P (x))
		   && is_overloaded_fn (t))
	    /* Don't do anything just yet.  */;
	  else if (t == wchar_decl_node)
            [...snip...]
	  else
	    {
	      tree olddecl = duplicate_decls (x, t, is_friend);

Later only the binding for such functions is compared, which doesn't
take default parameters into account (see line 778ff):

      if ((TREE_CODE (x) == FUNCTION_DECL)
	  && DECL_EXTERN_C_P (x)
          /* We should ignore declarations happening in system headers.  */
	  && !DECL_IN_SYSTEM_HEADER (x))
	{
	  cxx_binding *function_binding =
	      lookup_extern_c_fun_binding_in_all_ns (x);
	  if (function_binding
              && !DECL_IN_SYSTEM_HEADER (function_binding->value))
	    {
	      tree previous = function_binding->value;

	      /* In case either x or previous is declared to throw an exception,
	         make sure both exception specifications are equal.  */
	      if (decls_match (x, previous))
               [...snip...]
 
	    }
	}

      if (TREE_CODE (x) == FUNCTION_DECL || DECL_FUNCTION_TEMPLATE_P (x))
	check_default_args (x);

I'm not sure how to proceed from here, so unassigning.
Comment 13 Jason Merrill 2009-03-24 22:26:36 UTC
Subject: Bug 28274

Author: jason
Date: Tue Mar 24 22:26:21 2009
New Revision: 145042

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=145042
Log:
        PR c++/28274
        * name-lookup.c (pushdecl_maybe_friend): Check default args later.

Added:
    trunk/gcc/testsuite/g++.dg/parse/defarg14.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/name-lookup.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Jason Merrill 2009-03-24 22:27:13 UTC
Fixed for 4.4.
Comment 15 Joseph S. Myers 2009-03-31 19:39:46 UTC
Closing 4.2 branch.
Comment 16 Richard Biener 2009-08-04 12:27:52 UTC
GCC 4.3.4 is being released, adjusting target milestone.
Comment 17 Richard Biener 2010-05-22 18:11:09 UTC
GCC 4.3.5 is being released, adjusting target milestone.
Comment 18 Richard Biener 2011-06-27 11:09:46 UTC
Fixed for GCC 4.4.0.