public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sebor at roguewave dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/37064]  New: missing warning on pure function with side-effects
Date: Fri, 08 Aug 2008 19:45:00 -0000	[thread overview]
Message-ID: <bug-37064-1186@http.gcc.gnu.org/bugzilla/> (raw)

[-- 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


             reply	other threads:[~2008-08-08 19:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-08 19:45 sebor at roguewave dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-37064-1186@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).