[clang] C89 doesn't have `math.h` functions (PR #129979)
A. Jiang via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 18:51:53 PST 2025
frederick-vs-ja wrote:
> While `log` does exist since C89 _within <math.h>_, it should be allowed for a `.c` to define `int log = 0;` because the `math.h` has not been included. Thereby, even if `double log(double);` exists in C89 (in `math.h`), it's not been declared in the current translation unit, so declaring a symbol with the same name as `log` seems to be valid IMO.
However, declaration it as an object with _external_ linkage is UB (or ill-formed, no diagnostic required in the C++ standard wording).
Per [N3220](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) 7.1.3/1
> [...]
> — All identifiers with external linkage in any of the following subclauses (including the future library directions) and `errno` are always reserved for use as identifiers with external linkage.<sup>218)</sup>
> [...]
In C89 that was in 4.1.2
> [...] All external identifiers declared in any of the headers are reserved, whether or not the associated header is included. [...]
It seem to me that the following program was well-defined in C89 but became undefined (IFNDR) since C99.
```C
int logf = 0; /* N.B. static not used */
int main(void) { return logf; }
```
But if `logf` if replaced with `log`, the program is invalid even in C89.
https://github.com/llvm/llvm-project/pull/129979
More information about the cfe-commits
mailing list