From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20057 invoked by alias); 24 Feb 2011 11:16:02 -0000 Received: (qmail 20047 invoked by uid 22791); 24 Feb 2011 11:16:02 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 24 Feb 2011 11:15:56 +0000 From: "michal.t at tiscali dot it" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/47861] static variables inside member functions X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: trivial X-Bugzilla-Who: michal.t at tiscali dot it X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 24 Feb 2011 11:28:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg02749.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47861 --- Comment #10 from Michal Turlik 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: Ogg: [Bug c++/47861] static variables inside member functions http://gcc.gnu. org/bugzilla/show_bug.cgi?id=47861 --- Comment #8 from Jonathan Wakely 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.