public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19503] New: Parsing problem in the constructor call of temporary object
@ 2005-01-18 12:26 timo dot erkkila at tut dot fi
  2005-01-18 13:42 ` [Bug c++/19503] " gdr at integrable-solutions dot net
  2005-01-18 14:04 ` timo dot erkkila at tut dot fi
  0 siblings, 2 replies; 3+ messages in thread
From: timo dot erkkila at tut dot fi @ 2005-01-18 12:26 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

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 ); }

Yours,

Timo Erkkilä

Ps. g++ -v
Reading specs from
/share/local/lang/gcc342-sol7/bin/../lib/gcc/sparc-sun-solaris2.7/3.4.2/specs
Configured with: ../../gcc-3.4.2/configure --prefix=/opt/local/lang/gcc342-sol7
--enable-shared --enable-cpp --disable-threads --with-gnu-ld
--with-ld=/opt/local/lang/gcc342-sol7/bin/ld --with-gnu-as
--with-as=/opt/local/lang/gcc342-sol7/bin/as --with-cpu=supersparc --disable-nls
--disable-multilib --enable-c99 --enable-concept-checks --with-dwarf2
--enable-languages=c,c++
Thread model: single
gcc version 3.4.2

-- 
           Summary: Parsing problem in the constructor call of temporary
                    object
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: timo dot erkkila at tut dot fi
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: sparc-sun-solaris2.7


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/19503] Parsing problem in the constructor call of temporary object
  2005-01-18 12:26 [Bug c++/19503] New: Parsing problem in the constructor call of temporary object timo dot erkkila at tut dot fi
@ 2005-01-18 13:42 ` gdr at integrable-solutions dot net
  2005-01-18 14:04 ` timo dot erkkila at tut dot fi
  1 sibling, 0 replies; 3+ messages in thread
From: gdr at integrable-solutions dot net @ 2005-01-18 13:42 UTC (permalink / raw)
  To: gcc-bugs


------- 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" <gcc-bugzilla@gcc.gnu.org> 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/19503] Parsing problem in the constructor call of temporary object
  2005-01-18 12:26 [Bug c++/19503] New: Parsing problem in the constructor call of temporary object timo dot erkkila at tut dot fi
  2005-01-18 13:42 ` [Bug c++/19503] " gdr at integrable-solutions dot net
@ 2005-01-18 14:04 ` timo dot erkkila at tut dot fi
  1 sibling, 0 replies; 3+ messages in thread
From: timo dot erkkila at tut dot fi @ 2005-01-18 14:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From timo dot erkkila at tut dot fi  2005-01-18 14:04 -------
(In reply to comment #1)

Yes, I was also just given the following citations from the C++-standard:

8.2 Ambiguity resolution
1 "... Just as for the ambiguities mentioned in 6.8, the resolution is
   to consider any construct that could possibly be a declaration a
   declaration."

and

8.3 Meaning of declarators
6 "In a declaration
    T D
   where D has the form ( D1 ) the type of the contained declarator-id
   is the same as that of the contained declarator-id in the declaration
    T D1
   Parentheses do not alter the type of the embedded declarator-id, but
   they can alter the binding of complex declarators."

Anyway, that was new information to me, thanks!

++Timo E.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-01-18 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-18 12:26 [Bug c++/19503] New: Parsing problem in the constructor call of temporary object timo dot erkkila at tut dot fi
2005-01-18 13:42 ` [Bug c++/19503] " gdr at integrable-solutions dot net
2005-01-18 14:04 ` timo dot erkkila at tut dot fi

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).