public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/29834]  New: g++ thinks it is a declaration when it cannot be
@ 2006-11-14 16:36 james dot kanze at gmail dot com
  2006-11-14 21:33 ` [Bug c++/29834] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: james dot kanze at gmail dot com @ 2006-11-14 16:36 UTC (permalink / raw)
  To: gcc-bugs

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


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

end of thread, other threads:[~2024-02-07 17:57 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-29834-4@http.gcc.gnu.org/bugzilla/>
2012-10-11 21:54 ` [Bug c++/29834] g++ thinks it is a declaration when it cannot be pinskia at gcc dot gnu.org
2013-07-02 10:25 ` ace.of.zerosync at gmail dot com
2013-07-02 10:49 ` redi at gcc dot gnu.org
2013-07-02 12:10 ` ace.of.zerosync at gmail dot com
2013-07-02 15:04 ` james.kanze at gmail dot com
2013-07-02 17:16 ` manu at gcc dot gnu.org
2013-07-02 21:38 ` ace.of.zerosync at gmail dot com
2013-07-02 21:48 ` ace.of.zerosync at gmail dot com
2013-07-13  1:53 ` ace.of.zerosync at gmail dot com
2024-02-07 17:36 ` pinskia at gcc dot gnu.org
2024-02-07 17:57 ` mpolacek at gcc dot gnu.org
2006-11-14 16:36 [Bug c++/29834] New: " james dot kanze at gmail dot com
2006-11-14 21:33 ` [Bug c++/29834] " rguenth at gcc dot gnu dot org
2006-11-15  1:59 ` bangerth at dealii dot org
2006-11-15 10:05 ` james dot kanze at gmail dot com
2006-11-15 10:10 ` james dot kanze at gmail dot com

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