public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/37064] New: missing warning on pure function with side-effects
@ 2008-08-08 19:45 sebor at roguewave dot com
2008-08-08 19:49 ` [Bug c/37064] " sebor at roguewave dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: sebor at roguewave dot com @ 2008-08-08 19:45 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]
gcc assumes that functions defined with the pure attribute have no side
effects and do not modify program state, including through pointers passed
to such functions as arguments. The function below does modify the object
pointed to by its argument. It would be useful if gcc issued a diagnostic
for this and other similar violations of the "pure" assumption, analogously
to how it diagnoses noreturn functions that do return.
$ cat -n t.C && g++ -c -O2 -Wall -W t.C
1 int f0 () __attribute ((noreturn));
2 int f0 () { return 0; }
3
4 int f1 (int*) __attribute ((pure));
5 int f1 (int *i)
6 {
7 *i = 0;
8 return 0;
9 }
10
t.C: In function int f0():
t.C:2: warning: function declared noreturn has a return statement
t.C:2: warning: noreturn function does return
--
Summary: missing warning on pure function with side-effects
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sebor at roguewave dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37064
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37064] missing warning on pure function with side-effects
2008-08-08 19:45 [Bug c/37064] New: missing warning on pure function with side-effects sebor at roguewave dot com
@ 2008-08-08 19:49 ` sebor at roguewave dot com
2008-08-08 20:55 ` rguenth at gcc dot gnu dot org
2008-08-08 21:02 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: sebor at roguewave dot com @ 2008-08-08 19:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from sebor at roguewave dot com 2008-08-08 19:47 -------
Similarly, functions declared with the const attribute such as f1() in the
test case below that violate the compiler's assumptions should be diagnosed:
$ cat -n t.C && g++ -c -O2 -Wall -W t.C
1 extern int i;
2 int f1 () __attribute ((const));
3 int f1 ()
4 {
5 return i;
6 }
7
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37064
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37064] missing warning on pure function with side-effects
2008-08-08 19:45 [Bug c/37064] New: missing warning on pure function with side-effects sebor at roguewave dot com
2008-08-08 19:49 ` [Bug c/37064] " sebor at roguewave dot com
@ 2008-08-08 20:55 ` rguenth at gcc dot gnu dot org
2008-08-08 21:02 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-08-08 20:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2008-08-08 20:53 -------
Confirmed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2008-08-08 20:53:56
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37064
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/37064] missing warning on pure function with side-effects
2008-08-08 19:45 [Bug c/37064] New: missing warning on pure function with side-effects sebor at roguewave dot com
2008-08-08 19:49 ` [Bug c/37064] " sebor at roguewave dot com
2008-08-08 20:55 ` rguenth at gcc dot gnu dot org
@ 2008-08-08 21:02 ` pinskia at gcc dot gnu dot org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-08 21:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2008-08-08 21:01 -------
*** This bug has been marked as a duplicate of 18487 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37064
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-08 21:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-08 19:45 [Bug c/37064] New: missing warning on pure function with side-effects sebor at roguewave dot com
2008-08-08 19:49 ` [Bug c/37064] " sebor at roguewave dot com
2008-08-08 20:55 ` rguenth at gcc dot gnu dot org
2008-08-08 21:02 ` pinskia 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).