This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/29834] New: g++ thinks it is a declaration when it cannot be
- From: "james dot kanze at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Nov 2006 16:36:01 -0000
- Subject: [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
More cases where g++ apparently doesn't take
enough context into account when deciding that
something can be (and thus is) a declaration.
Compiled the following (legal) program using "g++ -c"
---------------------------------------
struct Doh
{
Doh( int ) {}
} ;
int x = 0 ;
int
f()
{
Doh( x ), ++ x ;
return Doh( x ), x ;
}
---------------------------------------
Got following errors:
---------------------------------------
parseError.cc: In function 'int f()':
parseError.cc:11: error: no matching function for call to 'Doh::Doh()'
parseError.cc:3: note: candidates are: Doh::Doh(int)
parseError.cc:2: note: Doh::Doh(const Doh&)
parseError.cc:11: error: expected unqualified-id before '++' token
parseError.cc:12: error: cannot convert 'Doh' to 'int' in return
---------------------------------------
Apparently, g++ is interpreting Doh( x ) as a declaration,
although in neither case is a declaration legal. (++x is not a
legal declarator, so the first line cannot be a declaration, and
of course, a declaration cannot start with the keyword return.)
(Note that in the actual code, Doh was boost::mutex::scoped_lock.
And I fear that using boost::mutex::scoped_lock like this is becoming
a widespread idiom.)
--
Summary: g++ thinks it is a declaration when it cannot be
Product: gcc
Version: 4.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: james dot kanze at gmail dot com
GCC build triplet: sparc-sun-solaris2.8
GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29834