------- Additional Comments From gdr at integrable-solutions dot net  
2005-01-18 13:40 -------
Subject: Re:  New: Parsing problem in the constructor call of temporary object

"timo dot erkkila at tut dot fi" <[EMAIL PROTECTED]> writes:

| Hello,
| 
| the following code
| 
|  struct A { };
|  struct B { B( A& ) { } };
| 
|  void foo( A& a ) { B( a ); }
| 
| results in this output:
|  g++ t.cc -c
| 
|  t.cc: In function `void foo(A&)':
|  t.cc:4: error: declaration of 'B a' shadows a parameter
|  t.cc:4: error: no matching function for call to `B::B()'
|  t.cc:2: note: candidates are: B::B(const B&)
|  t.cc:2: note:                 B::B(A&)
| 
| With a workaround (extra cast) in foo, it however compiles ok:
| 
|  void foo( A& a ) { B( (A&)a ); }

That is no error in the compiler.  
There is an ambiguity in the C++ grammar between declarations and
expression-statements.  The C++ standard rules that the ambiguity be
resolved in favor of declaration.  Therefore

    B(a);

is to be parsed as the declaration of a variable named "a", that requires
default-initialization (hence the second set of diagnostics).  Notice
that the redundant parenthesis around "a" is inherited from C.

-- Gaby


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19503

Reply via email to