https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87605
Bug ID: 87605 Summary: Ternary uses explicit copy constructor for lvalue-to-rvalue conversion Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: namark at disroot dot org Target Milestone: --- The code below compiles and outputs "copy" to stdout when ran. #include <cstdio> struct A { A(){} explicit A(const A&) {std::puts("copy");} }; int main() { A a; const A& b = true ? a : A(); return 0; } I'm using compiler version 8.1.0, but testing on godbolt.org all version available there, except 4.1.2, do the same. 4.1.2 will do it as well if the "const A& b = " is removed, leaving just the ternary by itself. This felt wrong to me, but I'm not very well versed in the standard, so asked on stack overflow https://stackoverflow.com/questions/52720175/ternary-allowed-to-call-an-explicit-copy-constructor-implicitly and the provided answer, confirming that this is a bug, seems correct.