public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33515] New: Inconsistent warning about "defined but not used"
@ 2007-09-21 5:57 mec at google dot com
2007-09-21 5:58 ` [Bug c++/33515] " mec at google dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: mec at google dot com @ 2007-09-21 5:57 UTC (permalink / raw)
To: gcc-bugs
Consider this code:
class Alpha { public: Alpha(); };
static Alpha* a1 = new Alpha;
Should this draw a warning about a1 defined-but-not-used? gcc 4.3-20070914
gives a warning on some programs but not others. Specifically, I see the
warning if a program has an unrelated syntax error. This is odd.
mec@hollerith:~/exp-defined$ cat z2.cc
class Alpha {
public:
Alpha();
~Alpha();
private:
int i;
};
static Alpha* a1 = new Alpha;
int Beta() {
return 0;
}
mec@hollerith:~/exp-defined$ /home/mec/gcc-4.3-20070914/install/bin/g++ -Wall
-S z2.cc
mec@hollerith:~/exp-defined$ cat z3.cc
class Alpha {
public:
Alpha();
~Alpha();
private:
int i;
};
static Alpha* a1 = new Alpha;
int Beta() {
return x;
}
mec@hollerith:~/exp-defined$ /home/mec/gcc-4.3-20070914/install/bin/g++ -Wall
-S z3.cc
z3.cc: In function 'int Beta()':
z3.cc:12: error: 'x' was not declared in this scope
z3.cc: At global scope:
z3.cc:9: warning: 'a1' defined but not used
mec@hollerith:~/exp-defined$
--
Summary: Inconsistent warning about "defined but not used"
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mec at google dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/33515] Inconsistent warning about "defined but not used"
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
@ 2007-09-21 5:58 ` mec at google dot com
2007-09-21 6:00 ` mec at google dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mec at google dot com @ 2007-09-21 5:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from mec at google dot com 2007-09-21 05:58 -------
Created an attachment (id=14236)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14236&action=view)
Test program
compile with: gcc -Wall -S z2.cc
This program does not give a warning about a1 defined-but-not-used. I believe
this is correct behavior.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/33515] Inconsistent warning about "defined but not used"
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
2007-09-21 5:58 ` [Bug c++/33515] " mec at google dot com
@ 2007-09-21 6:00 ` mec at google dot com
2007-09-21 9:08 ` [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: mec at google dot com @ 2007-09-21 6:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from mec at google dot com 2007-09-21 05:59 -------
Created an attachment (id=14237)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14237&action=view)
Test program
Compile with: gcc -Wall -S z3.cc
This program does give a warning about a1 defined-but-not-used. I believe this
is incorrect. The real point is that z2.cc and z3.cc should behave
consistently.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
2007-09-21 5:58 ` [Bug c++/33515] " mec at google dot com
2007-09-21 6:00 ` mec at google dot com
@ 2007-09-21 9:08 ` pinskia at gcc dot gnu dot org
2007-09-21 9:09 ` pinskia at gcc dot gnu dot org
2007-09-22 3:57 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-09-21 9:08 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2007-09-21 09:08 -------
I think there is already a bug about this.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Inconsistent warning about |Inconsistent warning about
|"defined but not used" |"defined but not used" when
| |there is an error
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
` (2 preceding siblings ...)
2007-09-21 9:08 ` [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error pinskia at gcc dot gnu dot org
@ 2007-09-21 9:09 ` pinskia at gcc dot gnu dot org
2007-09-22 3:57 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-09-21 9:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2007-09-21 09:09 -------
Yep, PR 32205.
*** This bug has been marked as a duplicate of 32205 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
` (3 preceding siblings ...)
2007-09-21 9:09 ` pinskia at gcc dot gnu dot org
@ 2007-09-22 3:57 ` bangerth at dealii dot org
4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2007-09-22 3:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from bangerth at dealii dot org 2007-09-22 03:57 -------
This code:
----------------
class Alpha { public: Alpha(); };
static Alpha* a1 = new Alpha;
----------------
should definitely not draw a warning because during the initialization
of the variable, the constructor of Alpha is run which could have side
effects. Doing stuff like this is actually a fairly frequently used
idiom whereby we can assure that certain resources are already allocated
before we even get to main().
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33515
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-09-22 3:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-21 5:57 [Bug c++/33515] New: Inconsistent warning about "defined but not used" mec at google dot com
2007-09-21 5:58 ` [Bug c++/33515] " mec at google dot com
2007-09-21 6:00 ` mec at google dot com
2007-09-21 9:08 ` [Bug c++/33515] Inconsistent warning about "defined but not used" when there is an error pinskia at gcc dot gnu dot org
2007-09-21 9:09 ` pinskia at gcc dot gnu dot org
2007-09-22 3:57 ` bangerth at dealii 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).