https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80783

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Ah.  For exit, GCC recognizes it as a built-in function and doesn't diagnose
it.    The same happens with puts for instance.  It should diagnose these.

For atoi, it's attribute pure that makes the difference, and the fact that the
function returns a value.  Attribute const has the same effect.  It looks to me
like calls to such finctions whose return value is unused are eliminated
(because they have no effect) before they can be checked.  This also seems like
a bug.  Let me change this back from enhancement to bug.

Note that it's not valid to declare extern "C" standard library functions like
free() to have a different type (like free(double)).  GCC recognizes many of
them as built-in functions and GCC 7 will warn about such conflicting
declarations with -Wbuiltin-declaration-mismatch.  This doesn't make this bug
report invalid, but it does mean that those test cases aren't really valid.

$ cat u.C && gcc -S -Wall -Wextra u.C
int foo () __attribute__ ((__pure__));

constexpr int f () { foo (); return 0; }

int bar ();

constexpr int g () { bar (); return 0; }

u.C: In function ‘constexpr int f()’:
u.C:3:26: warning: statement has no effect [-Wunused-value]
 constexpr int f () { foo (); return 0; }
                      ~~~~^~
u.C: In function ‘constexpr int g()’:
u.C:7:26: error: call to non-constexpr function ‘int bar()’
 constexpr int g () { bar (); return 0; }
                      ~~~~^~

Reply via email to