[clang] C89 doesn't have `math.h` functions (PR #129979)
Vinay Deshmukh via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 6 17:50:03 PST 2025
vinay-deshmukh wrote:
> > Essentially all of math.h doesn't exist until `C99`: https://en.cppreference.com/w/c/numeric/math/log
>
> You seemed to misread the page. `logf` and `logl` exist since C99, while `log` exists since C89.
@frederick-vs-ja
My bad, I should have better clarified my previous comment.
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.
GCC's behavior seems to be that even if builtins are "re-defined" it is allowed, _when_ there is no explicit include for `math.h`
# Reference:
I've made a godbolt link https://godbolt.org/z/zY76dWa84 with all the symbols on https://en.cppreference.com/w/c/numeric/math
All panels have `-std=c89` in common and are the respective `trunk` versions.
1. Panel 1: GCC builds with warnings `[-Wbuiltin-declaration-mismatch]`
2. Panel 2: Clang builds (after passing non-default options, this PR will make those effective when using `-std=c89`) and no warnings despite `-Wall`
3. Panel 3: Clang fails to build (this issue)
https://github.com/llvm/llvm-project/pull/129979
More information about the cfe-commits
mailing list