public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32205]  New: "defined but not used" warning given or not depending on other errors
@ 2007-06-04 13:16 vz-gcc at zeitlins dot org
  2007-06-06 21:48 ` [Bug c++/32205] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vz-gcc at zeitlins dot org @ 2007-06-04 13:16 UTC (permalink / raw)
  To: gcc-bugs

Consider the following code:

% cat unused.cpp
static int GetFoo() { return 17; }

static int foo = GetFoo();

void bar()
{
}

This compiles without warnings:

% g++ -Wall -c unused.cpp
%

However if any error is introduced, like e.g. removing the closing brace of the
bar() function, then we get both the (expected) error message and (less
expected) warning:

% g++ -Wall -c unused.cpp
unused.cpp: In function 'void bar()':
unused.cpp:6: error: expected `}' at end of input
unused.cpp: At global scope:
unused.cpp:3: warning: 'foo' defined but not used


I don't know if the warning should or not be given (actually I'm glad to not
have it in my code as my equivalent of GetFoo() has side effects) but it seems
strange that the fact whether it's given or not depends on whether there are
any other errors in the code.

I realize this is not very important (hence the choice of severity) but I
wanted to let you know about it in case this indicates some more serious
problem with issuing this warning. Please feel free to ignore this bug report
if it doesn't.

Thanks!


-- 
           Summary: "defined but not used" warning given or not depending on
                    other errors
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vz-gcc at zeitlins dot org
  GCC host triplet: x86_64-unknown-linux-gnu


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


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

* [Bug c++/32205] "defined but not used" warning given or not depending on other errors
  2007-06-04 13:16 [Bug c++/32205] New: "defined but not used" warning given or not depending on other errors vz-gcc at zeitlins dot org
@ 2007-06-06 21:48 ` pinskia at gcc dot gnu dot org
  2007-09-21  9:09 ` pinskia at gcc dot gnu dot org
  2010-02-20 23:56 ` manu at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-06 21:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-06-06 21:48 -------
The main reason why is that we don't process the initializer for foo if we get
an error.


-- 


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


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

* [Bug c++/32205] "defined but not used" warning given or not depending on other errors
  2007-06-04 13:16 [Bug c++/32205] New: "defined but not used" warning given or not depending on other errors vz-gcc at zeitlins dot org
  2007-06-06 21:48 ` [Bug c++/32205] " pinskia at gcc dot gnu dot org
@ 2007-09-21  9:09 ` pinskia at gcc dot gnu dot org
  2010-02-20 23:56 ` manu at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-09-21  9:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-09-21 09:09 -------
*** Bug 33515 has been marked as a duplicate of this bug. ***


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mec at google dot com


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


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

* [Bug c++/32205] "defined but not used" warning given or not depending on other errors
  2007-06-04 13:16 [Bug c++/32205] New: "defined but not used" warning given or not depending on other errors vz-gcc at zeitlins dot org
  2007-06-06 21:48 ` [Bug c++/32205] " pinskia at gcc dot gnu dot org
  2007-09-21  9:09 ` pinskia at gcc dot gnu dot org
@ 2010-02-20 23:56 ` manu at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-20 23:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from manu at gcc dot gnu dot org  2010-02-20 23:56 -------
(In reply to comment #1)
> The main reason why is that we don't process the initializer for foo if we get
> an error.

What? Don't we process the initializer of foo before processing bar()? That is
weird. 

But we still parse that foo is initialized, so there should be no warning.

This is confirmed in trunk.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   GCC host triplet|x86_64-unknown-linux-gnu    |
      Known to fail|                            |4.4.0
   Last reconfirmed|0000-00-00 00:00:00         |2010-02-20 23:56:36
               date|                            |


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


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

end of thread, other threads:[~2010-02-20 23:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-04 13:16 [Bug c++/32205] New: "defined but not used" warning given or not depending on other errors vz-gcc at zeitlins dot org
2007-06-06 21:48 ` [Bug c++/32205] " pinskia at gcc dot gnu dot org
2007-09-21  9:09 ` pinskia at gcc dot gnu dot org
2010-02-20 23:56 ` manu at gcc dot gnu dot org

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