https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110938
Bug ID: 110938 Summary: miscompile if implicit special member is deleted in a subtle way Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: richard-gccbugzilla at metafoo dot co.uk Target Milestone: --- Testcase: https://godbolt.org/z/rKG8c166f ``` template<typename T> struct Error { //static_assert(false); using type = T; }; template<typename T> using ArbitraryComputation = typename Error<T>::type; struct X { template<typename T = X> X(ArbitraryComputation<T> &) = delete; X(const X&) = default; X(X&&) = delete; }; struct Y { #if 0 Y(const Y&) = default; Y(Y&&) = default; #endif mutable X x; int n; }; void print(int); Y f(); void g() { print(f().n); } ``` Uncommenting the `static_assert`, we can see that GCC never instantiates `Error<X>` in this example. But it must! If `ArbitraryComputation<X>` evaluates to `T`, then the non-trivial, templated constructor in `X` is used to copy the member `Y::x`, so `Y` is not trivially-copyable. This issue affects both type traits (GCC incorrectly evaluates `__is_trivially_copyable(Y)` to true) and code generation (GCC emits `f()` as returning in registers, which is both non-compliant with the ABI and doesn't follow the C++ language rules because `Y` has no trivial copy or move constructor). If the `#if 0` is changed to `#if 1`, the problem disappears.