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

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