https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115808
Bug ID: 115808
Summary: Different behavior with optimizations enabled and
disabled.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: linuxnyasha at tutanota dot com
Target Milestone: ---
```cpp
#include <tuple>
namespace utempl::loopholes {
template <auto I>
struct Getter {
friend constexpr auto Magic(Getter<I>);
};
template <auto I, auto Value = 0>
struct Injector {
friend constexpr auto Magic(Getter<I>) {
return Value;
};
};
} // namespace utempl::loopholes
namespace utempl {
template <typename... Ts>
struct TypeList {};
} // namespace utempl
struct SomeStruct {
constexpr SomeStruct(auto&& arg) {
arg.Method(42);
};
};
struct Injector {
template <typename T, auto _ = utempl::loopholes::Injector<0,
utempl::TypeList<T>{}>{}>
auto Method(T&&) const -> void;
};
template <typename T, auto... Args>
inline constexpr auto Use() {
std::ignore = T{Args...};
};
template <typename...>
consteval auto Ignore() {};
auto main() -> int {
Ignore<decltype(Use<SomeStruct, Injector{}>())>();
static_assert(std::is_same_v<decltype(Magic(utempl::loopholes::Getter<0>{})),
utempl::TypeList<int>>); // Passes with optimizations. Not passes without
};
```
I'm interested in static_assert always passing and code always compiling,
regardless of whether optimizations are enabled or not.
https://godbolt.org/z/WvKGvGEnK