public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/62244] New: Function parameter should be in scope in its own default argument
@ 2014-08-24 8:49 zeratul976 at hotmail dot com
2014-08-26 11:12 ` [Bug c++/62244] " redi at gcc dot gnu.org
2024-04-04 6:59 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: zeratul976 at hotmail dot com @ 2014-08-24 8:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62244
Bug ID: 62244
Summary: Function parameter should be in scope in its own
default argument
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: zeratul976 at hotmail dot com
Consider the following code:
int a;
void f(int a = a);
GCC accepts this code, and name lookup for the 'a' in the default argument
finds the global variable 'a' (as suggested by the fact that if the global
variable 'a' is commented out, GCC now gives "error: 'a' was not declared in
this scope").
I believe this in incorrect. During name lookup for the 'a' in the default
argument, the parameter 'a' should already be in scope, since
[basic.scope.pdecl]/p1 says that "The point of declaration for a name is
immediately after its complete declarator and before its initializer (if any)".
Once name lookup finds the parameter, the program should then be ill-formed,
because [dcl.fct.default]/p9 says "parameters of a function shall not be used
in a default argument".
Note that GCC has the correct behaviour when a later parameter's default
argument references an earlier parameter:
int a;
void f(int a, int b = a); // error: local variable 'a' may not appear in this
context
The incorrect behaviour only occurs when a parameter's own default argument
references the parameter.
Note that clang rejects the first example with "error: default argument
references parameter 'a'".
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/62244] Function parameter should be in scope in its own default argument
2014-08-24 8:49 [Bug c++/62244] New: Function parameter should be in scope in its own default argument zeratul976 at hotmail dot com
@ 2014-08-26 11:12 ` redi at gcc dot gnu.org
2024-04-04 6:59 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: redi at gcc dot gnu.org @ 2014-08-26 11:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62244
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-08-26
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/62244] Function parameter should be in scope in its own default argument
2014-08-24 8:49 [Bug c++/62244] New: Function parameter should be in scope in its own default argument zeratul976 at hotmail dot com
2014-08-26 11:12 ` [Bug c++/62244] " redi at gcc dot gnu.org
@ 2024-04-04 6:59 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-04 6:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62244
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |smcallis at gmail dot com
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 84373 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-04 6:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-24 8:49 [Bug c++/62244] New: Function parameter should be in scope in its own default argument zeratul976 at hotmail dot com
2014-08-26 11:12 ` [Bug c++/62244] " redi at gcc dot gnu.org
2024-04-04 6:59 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).