This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: bogus error on constructor call with gcc 2.95.2
- To: Alexandre Oliva <aoliva at redhat dot com>
- Subject: Re: bogus error on constructor call with gcc 2.95.2
- From: Martin Sebor <sebor at roguewave dot com>
- Date: Sun, 15 Oct 2000 22:52:16 -0600
- CC: "E. Jay Berkenbilt" <ejb at ql dot org>, gcc-bugs at gcc dot gnu dot org
- Organization: Rogue Wave Software, Inc.
- References: <200010160312.XAA02497@soup.ql.org> <or66mt79p8.fsf@guarana.lsd.ic.unicamp.br>
Alexandre Oliva wrote:
>
> On Oct 16, 2000, "E. Jay Berkenbilt" <ejb@ql.org> wrote:
>
> > B(A(0, 1));
>
> This is not what you think it is. In C++, this is the same as:
>
> B A(0, 1);
>
> i.e., a declaration and definition of a variable named A, of type B,
> initialized using a B's constructor that takes two arguments that can
> be implicitly converted from `0' and `1', respectively.
I respectfully disagree. The above is just what the original poster
said: an expression statement consisting of an unnamed temporary of type
B constructed from another temporary of type A.
From the grammar:
simple-declaration:
decl-specifier-seq[opt] init-declarator-list[opt] ;
init-declarator-list:
init-declarator
init-declarator-list, init-declarator
init-declarator:
declarator initializer[opt]
declarator:
direct-declarator
ptr-operator-declarator
direct-declarator:
declarator-id
direct-declarator (parameter-declaration-clause) ...
direct-declarator [constant-expression[opt]]
(declarator)
declarator-id:
id-expression
B is then the decl-specifier-seq, but (A(0, 1)) can't be an
init-declarator because it's parenthesized (only the declarator can be
parenthesized, not the whole thing). Instead, the whole thing is an
expression-statement.
Regards
Martin
>
> If you want to construct a temporary, casting it to void or anything
> else that disambiguates the statement so that it is cannot be
> interpreted as a declaration should be fine.
>
> --
> Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
> Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
> CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
> Free Software Evangelist *Please* write to mailing lists, not to me