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

--- Comment #2 from Victor Nawothnig <victor.nawothnig at gmail dot com> ---
Except all the following examples violate the core constant expression
constraint ([expr.const] 2.3), but GCC diagnoses only some:

```
$ echo '#include <cstdlib> \n constexpr int f() { atoi(""); return 1; }' |
g++-6 -x c++ -c -
<stdin>: In function 'constexpr int f()':
<stdin>:2:26: error: call to non-constexpr function 'int atoi(const char*)'
$ echo '#include <cstdlib> \n constexpr int f() { atexit(0); return 1; }' |
g++-6 -x c++ -c -
<stdin>: In function 'constexpr int f()':
<stdin>:2:28: error: call to non-constexpr function 'int atexit(void (*)())'
$ echo 'void g(); constexpr int f() { g(); return 1; }' | g++-6 -x c++ -c -
<stdin>: In function 'constexpr int f()':
<stdin>:1:32: error: call to non-constexpr function 'void g()'
$ echo '#include <cstdlib> \n constexpr int f() { calloc(0,0); return 1; }' |
g++-6 -x c++ -c -
(success)
$ echo '#include <cstdlib> \n constexpr int f() { malloc(0); return 1; }' |
g++-6 -x c++ -c -
(success)
$ echo '#include <cstdlib> \n constexpr int f() { free(0); return 1; }' | g++-6
-x c++ -c -
(success)
```


And regarding your last argument, here is to show that this is not the case. It
seems like something about the signature influences how GCC applies its
constexpr diagnostic.
```
$ echo 'extern "C" void free(void *); constexpr int f() { free(0); return 1; }'
| g++-6 -x c++ -c -
(success)
$ echo 'extern "C" int free(double); constexpr int f() { free(0); return 1; }'
| g++-6 -x c++ -c -
<stdin>: In function 'constexpr int f()':
<stdin>:1:54: error: call to non-constexpr function 'int free(double)'
```
```
$ echo 'extern "C" void exit (int); constexpr int f() { exit(0); return 1; }' |
g++-6 -x c++ -c -
(success)
$ echo 'extern "C" void exit (double); constexpr int f() { exit(0); return 1;
}' | g++-6 -x c++ -c -
<stdin>: In function 'constexpr int f()':
<stdin>:1:56: error: call to non-constexpr function 'void exit(double)'
```

That test came from trying to narrow it down to either the libstdc++-v3 or g++.

Reply via email to