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; 5+ 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] 5+ messages in thread
* [Bug c++/29834] g++ thinks it is a declaration when it cannot be
2006-11-14 16:36 [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be james dot kanze at gmail dot com
@ 2006-11-14 21:33 ` rguenth at gcc dot gnu dot org
2006-11-15 1:59 ` bangerth at dealii dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-11-14 21:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2006-11-14 21:33 -------
I you use
( Doh ( x ) ), ++ x;
it works. (EDG accepts the code unmodified)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29834
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/29834] g++ thinks it is a declaration when it cannot be
2006-11-14 16:36 [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be 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
3 siblings, 0 replies; 5+ messages in thread
From: bangerth at dealii dot org @ 2006-11-15 1:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from bangerth at dealii dot org 2006-11-15 01:59 -------
Confirmed.
> (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.)
Ugh, this isn't an easy to read idiom...
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2006-11-15 01:59:29
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29834
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/29834] g++ thinks it is a declaration when it cannot be
2006-11-14 16:36 [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be 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
3 siblings, 0 replies; 5+ messages in thread
From: james dot kanze at gmail dot com @ 2006-11-15 10:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from james dot kanze at gmail dot com 2006-11-15 10:05 -------
Subject: Re: g++ thinks it is a declaration when it cannot be
On 14 Nov 2006 21:33:34 -0000, rguenth at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
> I you use
> ( Doh ( x ) ), ++ x;
> it works.
I know. I don't consider it a critical error, but it is legal
code, so formally, at least, the compiler should accept it.
> (EDG accepts the code unmodified)
So does Sun CC and VC++.
If I remember correctly, in the past, g++ has had problems with
opting too soon for the declaration, before having seen enough
of the context to know that it couldn't be. I suspect that this
is just a case of the correction having missed a couple of
cases.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29834
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/29834] g++ thinks it is a declaration when it cannot be
2006-11-14 16:36 [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be james dot kanze at gmail dot com
` (2 preceding siblings ...)
2006-11-15 10:05 ` james dot kanze at gmail dot com
@ 2006-11-15 10:10 ` james dot kanze at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: james dot kanze at gmail dot com @ 2006-11-15 10:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from james dot kanze at gmail dot com 2006-11-15 10:10 -------
Subject: Re: g++ thinks it is a declaration when it cannot be
On 15 Nov 2006 01:59:33 -0000, bangerth at dealii dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
> > (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.)
> Ugh, this isn't an easy to read idiom...
Not sure I like it myself. It has two advantages: you don't
have to invent a name for a variable that you are never going to
use, and you don't have to add braces to limit the scope of the
lock. Very meager advantages, IMHO: it doesn't bother me to
just throw in any short name (e.g. 'l') in such cases, and if
the function is large enough to require the extra braces, it's
probably too large and complicated anyway.
But I'm not the only programmer in the world, and some people
seem to actually like it. And... I'll use it too, in quick
hacks in throw-away code.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29834
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-11-15 10:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-14 16:36 [Bug c++/29834] New: g++ thinks it is a declaration when it cannot be 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).