This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/37064] New: missing warning on pure function with side-effects


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]