https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121231
Bug ID: 121231
Summary: [13->trunk] miscompile with brace-initialized constant
template parameter perhaps due to function coalescing
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gasper.azman at gmail dot com
Target Milestone: ---
Came across this one today:
(godbolt: https://godbolt.org/z/G4vK3b59W)
```
#include <iostream>
struct Foo
{
int a;
int b;
};
constexpr Foo make_foo(bool x) {
Foo result{};
if (x) {
result.a = 1;
} else {
result.b = 1;
}
return result;
}
template<Foo FOO>
void bar() {
std::cout << FOO.a << " " << FOO.b << std::endl;
}
template<bool x>
void foo()
{
constexpr Foo FOO = make_foo(x);
std::cout << FOO.a << " " << FOO.b << std::endl;
bar<FOO>();
}
void do_false() { // if you remove this function, the bug goes away
foo<false>();
}
int main()
{
foo<true>();
return 0;
}
```
prints
Program returned: 0
1 0
0 1
despite the fact that /both/ `cout`s should print at least the same thing.
This is true at least on 13 and current godbolt trunk.
Note - if you remove `foo<false>()` the bug goes away (it's not invoked, even),
so I'm guessing it's some function cache folding/wrong comparison thing.
Thanks all,
G