This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/47861] static variables inside member functions


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

--- Comment #10 from Michal Turlik <michal.t at tiscali dot it> 2011-02-24 11:15:51 UTC ---
redi,
the signatures where wrong, the correct ones are:
Base* Base::next
(bool)
void Base::init()

btw you got the point - I mean you understood 
how the code buggy is.

a better warning should be:
oo.cc:4:3: Warning: 
'it' is declared as a function-scope static, you mean a static member 
variable?
oo.cc:4:3: Warning: 'it' is declared as a function-scope 
static, error prone, see static member variables

Honestly this would 
be prevent if the compiler was going to search for the static var 
definition.



----Messaggio originale----
Da: gcc-bugzilla@gcc.gnu.org

Data: 24/02/2011 11.44
A: <michal.t@tiscali.it>
Ogg: [Bug c++/47861] 
static variables inside member functions

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

--- Comment #8 from Jonathan Wakely 
<redi at gcc dot gnu.org> 2011-02-24 10:44:15 UTC ---
(In reply to 
comment #7)
> The issue is clearly caused by having 
> declared static 
the iterator.

So that's a bug, don't do that.

> Obviously the same 
snippet code can be 
> replaced by a simple for each iterator 
construct.
> As you have mentioned 
> before - static means static...
consider only the implication of a code 
> written in this way...a 
> 
forced definition of the iterator being static 
> would probably 
prevent some unprapred c++ users to make similar 
> mistakes.

I don't 
understand, are you now suggesting the local static should be turned

into a static member by the compiler?!

Again, please explain what 
warning you want. So far you've shown some buggy
code, but haven't 
explained how GCC could help prevent users from creating that
bug.

e.
g.

foo.cc:4:3: In 'MyClass::next(bool)':
foo.cc:4:3: Warning: 'it' is 
declared as a function-scope static, did you want
to use a static 
member variable?

For the record, I would be strongly-opposed to such a 
warning.

There are a million ways to write code that is buggy, the 
compiler cannot
possibly infer what you really wanted to do and suggest 
how to fix all bugs.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]