[clang] [clang] Fix -Wdouble-promotion in C++ list-initialization (PR #159992)
Marcel Jacobse via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 21 14:40:46 PDT 2025
mjacobse wrote:
Thanks, your `struct B` example raises a very good point, because with this PR no warning would be thrown anymore for the promotion of `f` to `double` in the initialization of member `B::d`. Using parantheses
```c++
B(float f) : d(f) {}
```
would bring back the warning. Something similar happens with local variable initialization too:
```c++
void test(float f) {
double d0 = f;
double d1(f);
double d2{f};
}
```
Before this PR, all three initializations give the warning. After this PR, `d0` and `d1` give the warning but `d2` doesn't.
I could see an argument for `d1` and `d2` not to issue a warning, but them behaving differently does seem wrong. For the member initializer list it seems more clear-cut that the warning is desirable, with the declaration as `double` and the initialization being split apart.
https://github.com/llvm/llvm-project/pull/159992
More information about the cfe-commits
mailing list