Bug 49692 - Constructor call mistaken for declaration
Summary: Constructor call mistaken for declaration
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-09 21:10 UTC by John Kortink
Modified: 2011-07-10 04:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Kortink 2011-07-09 21:10:13 UTC
The compiler interprets

MyObject(variable_name)

as

MyObject variable_name

If variable_name exists as an int, this causes a 'redeclaration' error instead of a call to the constructor MyObject::MyObject(int).

Am I missing some syntactic aspect here ? The root cause may very well be that e.g.

int (variable_name)

is accepted by the compiler as a declaration. It doesn't look like one to me.
Comment 1 Andreas Schwab 2011-07-09 21:39:28 UTC
Redundant parens are always possible.
Comment 2 John Kortink 2011-07-09 23:08:02 UTC
(In reply to comment #1)
> Redundant parens are always possible.

They shouldn't always be possible. It is a laxity in the grammar that needlessly causes context dependencies. And, in this case, rejection of a perfectly valid language construct.

Even if the context dependency is not removed, the interpretation of 'classname (variablename)' as a constructor call should be considered by the parser.
Comment 3 Jonathan Wakely 2011-07-10 04:28:04 UTC
http://en.wikipedia.org/wiki/Most_vexing_parse