public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/15083] New: spurious "statement has no effect" warning
@ 2004-04-22 23:23 carlton at bactrian dot org
2004-04-22 23:38 ` [Bug c++/15083] " carlton at bactrian dot org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: carlton at bactrian dot org @ 2004-04-22 23:23 UTC (permalink / raw)
To: gcc-bugs
When I compile the following program with g++ -Wall (where g++ is the
released 3.4.0), I get the following warning:
quartette$ /net/quartette/carlton/gcc/gcc-3.4.0/install/bin/g++ -Wall test.cpp
test.cpp: In member function `void Foo<T>::resetData()':
test.cpp:31: warning: statement has no effect
The line in question is this one:
new ( refLoc ) Counter();
but Counter's contructor does have a side effect. (Indeed, the output
of the program changes if you compile out that line.)
Here's the source code; I'll attach a .ii file as well. (The .ii
file is kind of large, because I include <iostream> to show that
the line in question does indeed change the behavior of the program.)
#include <new>
#include <iostream>
class Counter {
public:
void decrement() { --ref_; }
Counter() : ref_(1) {}
int ref() const {
return ref_;
}
private:
int ref_;
};
template< typename T >
class Foo {
public:
void resetData() {
ref_.decrement();
std::cout << "before: " << ref_.ref() << std::endl;
ref_.~Counter();
void *refLoc = &ref_;
// GCC erroneously claims that the following line has no
// effect. But it does have an effect: the value of the
// "after" message will be 0 instead of 1 if you comment it
// out.
new ( refLoc ) Counter();
std::cout << "after: " << ref_.ref() << std::endl;
}
private:
Counter ref_;
};
int main() {
Foo< int > node;
node.resetData();
}
--
Summary: spurious "statement has no effect" warning
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: carlton at bactrian dot org
CC: gcc-bugs at gcc dot gnu dot org
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=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
@ 2004-04-22 23:38 ` carlton at bactrian dot org
2004-04-22 23:43 ` carlton at bactrian dot org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: carlton at bactrian dot org @ 2004-04-22 23:38 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From carlton at bactrian dot org 2004-04-22 23:21 -------
Created an attachment (id=6143)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6143&action=view)
preprocessed source
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
2004-04-22 23:38 ` [Bug c++/15083] " carlton at bactrian dot org
@ 2004-04-22 23:43 ` carlton at bactrian dot org
2004-04-22 23:46 ` carlton at bactrian dot org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: carlton at bactrian dot org @ 2004-04-22 23:43 UTC (permalink / raw)
To: gcc-bugs
--
What |Removed |Added
----------------------------------------------------------------------------
Attachment #6143|application/octet-stream |text/plain
mime type| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
2004-04-22 23:38 ` [Bug c++/15083] " carlton at bactrian dot org
2004-04-22 23:43 ` carlton at bactrian dot org
@ 2004-04-22 23:46 ` carlton at bactrian dot org
2004-04-22 23:49 ` carlton at bactrian dot org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: carlton at bactrian dot org @ 2004-04-22 23:46 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From carlton at bactrian dot org 2004-04-22 23:22 -------
Created an attachment (id=6144)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=6144&action=view)
unpreprocessed source
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (2 preceding siblings ...)
2004-04-22 23:46 ` carlton at bactrian dot org
@ 2004-04-22 23:49 ` carlton at bactrian dot org
2004-04-22 23:51 ` [Bug c++/15083] [3.4/3.5 Regression]spurious " pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: carlton at bactrian dot org @ 2004-04-22 23:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From carlton at bactrian dot org 2004-04-22 23:38 -------
By the way, this is a regression - it works with GCC 3.2.3. (I haven't
tried it with other GCC versions.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (3 preceding siblings ...)
2004-04-22 23:49 ` carlton at bactrian dot org
@ 2004-04-22 23:51 ` pinskia at gcc dot gnu dot org
2004-05-06 23:23 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-22 23:51 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-04-22 23:43 -------
Confirmed, here is the reduced source:
extern "C" int printf(const char*,...);
void *operator new(__SIZE_TYPE__, void*);
struct Counter {
Counter(){printf("Hello World.\n");}
};
void *t;
template< typename T >
void resetData() {
new ( t) Counter();
}
int main() {
resetData<int>();
}
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Keywords| |diagnostic
Known to fail| |3.4.0 3.5.0
Known to work| |3.3.3
Last reconfirmed|0000-00-00 00:00:00 |2004-04-22 23:43:41
date| |
Summary|spurious "statement has no |[3.4/3.5 Regression]spurious
|effect" warning |"statement has no effect"
| |warning
Target Milestone|--- |3.4.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (4 preceding siblings ...)
2004-04-22 23:51 ` [Bug c++/15083] [3.4/3.5 Regression]spurious " pinskia at gcc dot gnu dot org
@ 2004-05-06 23:23 ` pinskia at gcc dot gnu dot org
2004-05-06 23:26 ` pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-06 23:23 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-06 23:23 -------
*** Bug 15333 has been marked as a duplicate of this bug. ***
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |ofv at wanadoo dot es
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (5 preceding siblings ...)
2004-05-06 23:23 ` pinskia at gcc dot gnu dot org
@ 2004-05-06 23:26 ` pinskia at gcc dot gnu dot org
2004-05-29 16:19 ` mmitchel at gcc dot gnu dot org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-06 23:26 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-06 23:26 -------
Here is another case (dervided from this PR and PR 15333):
extern "C" int printf(const char*,...);
struct Counter {
Counter(){printf("Hello World.\n");}
};
template< typename T >
void resetData() {
new Counter();
}
int main() {
resetData<int>();
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (6 preceding siblings ...)
2004-05-06 23:26 ` pinskia at gcc dot gnu dot org
@ 2004-05-29 16:19 ` mmitchel at gcc dot gnu dot org
2004-05-30 1:58 ` cvs-commit at gcc dot gnu dot org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-05-29 16:19 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-05-28 21:28 -------
Working on a fix.
--
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |mark at codesourcery dot com
|dot org |
Status|NEW |ASSIGNED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (7 preceding siblings ...)
2004-05-29 16:19 ` mmitchel at gcc dot gnu dot org
@ 2004-05-30 1:58 ` cvs-commit at gcc dot gnu dot org
2004-05-30 3:58 ` cvs-commit at gcc dot gnu dot org
2004-05-30 7:49 ` mmitchel at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 1:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 22:29 -------
Subject: Bug 15083
CVSROOT: /cvs/gcc
Module name: gcc
Branch: gcc-3_4-branch
Changes by: mmitchel@gcc.gnu.org 2004-05-28 22:29:44
Modified files:
gcc/cp : ChangeLog decl2.c init.c name-lookup.c typeck.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/expr: ptrmem4.C
gcc/testsuite/g++.dg/template: operator3.C
gcc/testsuite/g++.dg/warn: noeffect5.C
Log message:
PR c++/15083
* decl2.c (delete_sanity): Set TREE_SIDE_EFFECTS on a DELETE_EXPR,
even in a templat.e
* init.c (build_new): Likewise.
PR c++/15640
* name-lookup.c (arg_assoc): Robustify.
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
PR c++/15083
* g++.dg/warn/noeffect5.C: New test.
PR c++/15471
* g++.dg/expr/ptrmem4.C: New test.
PR c++/15640
* g++.dg/template/operator3.C: New test.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.107&r2=1.3892.2.108
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.695.4.7&r2=1.695.4.8
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.356.2.9&r2=1.356.2.10
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.2.12&r2=1.34.2.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.519.2.16&r2=1.519.2.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.185&r2=1.3389.2.186
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem4.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator3.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/noeffect5.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.2.4.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (8 preceding siblings ...)
2004-05-30 1:58 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 3:58 ` cvs-commit at gcc dot gnu dot org
2004-05-30 7:49 ` mmitchel at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-05-30 3:58 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From cvs-commit at gcc dot gnu dot org 2004-05-28 22:35 -------
Subject: Bug 15083
CVSROOT: /cvs/gcc
Module name: gcc
Changes by: mmitchel@gcc.gnu.org 2004-05-28 22:35:50
Modified files:
gcc/cp : ChangeLog decl2.c init.c name-lookup.c typeck.c
gcc/testsuite : ChangeLog
Added files:
gcc/testsuite/g++.dg/expr: ptrmem4.C
gcc/testsuite/g++.dg/template: operator3.C
gcc/testsuite/g++.dg/warn: noeffect6.C
Log message:
PR c++/15083
* decl2.c (delete_sanity): Set TREE_SIDE_EFFECTS on a DELETE_EXPR,
even in a templat.e
* init.c (build_new): Likewise.
PR c++/15640
* name-lookup.c (arg_assoc): Robustify.
PR c++/15471
* typeck.c (unary_complex_lvalue): Use context_for_name_lookup
when determining the scope to use for a pointer to member.
PR c++/15083
* g++.dg/warn/noeffect5.C: New test.
PR c++/15471
* g++.dg/expr/ptrmem4.C: New test.
PR c++/15640
* g++.dg/template/operator3.C: New test.
Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4064&r2=1.4065
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.709&r2=1.710
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.370&r2=1.371
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.54&r2=1.55
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/typeck.c.diff?cvsroot=gcc&r1=1.544&r2=1.545
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3789&r2=1.3790
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/expr/ptrmem4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/operator3.C.diff?cvsroot=gcc&r1=1.1&r2=1.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/noeffect6.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/15083] [3.4/3.5 Regression]spurious "statement has no effect" warning
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
` (9 preceding siblings ...)
2004-05-30 3:58 ` cvs-commit at gcc dot gnu dot org
@ 2004-05-30 7:49 ` mmitchel at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2004-05-30 7:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2004-05-28 23:35 -------
Fixed in GCC 3.4.1.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15083
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2004-05-28 23:35 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-22 23:23 [Bug c++/15083] New: spurious "statement has no effect" warning carlton at bactrian dot org
2004-04-22 23:38 ` [Bug c++/15083] " carlton at bactrian dot org
2004-04-22 23:43 ` carlton at bactrian dot org
2004-04-22 23:46 ` carlton at bactrian dot org
2004-04-22 23:49 ` carlton at bactrian dot org
2004-04-22 23:51 ` [Bug c++/15083] [3.4/3.5 Regression]spurious " pinskia at gcc dot gnu dot org
2004-05-06 23:23 ` pinskia at gcc dot gnu dot org
2004-05-06 23:26 ` pinskia at gcc dot gnu dot org
2004-05-29 16:19 ` mmitchel at gcc dot gnu dot org
2004-05-30 1:58 ` cvs-commit at gcc dot gnu dot org
2004-05-30 3:58 ` cvs-commit at gcc dot gnu dot org
2004-05-30 7:49 ` mmitchel 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).