https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100720
Bug ID: 100720 Summary: inconsistent return type deduction behavior with user defined conversion function Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nickgray0 at brown dot edu Target Milestone: --- the following code compiles successfully: auto f(auto); template<typename = int> struct A { auto g() { return f(0); } }; auto f(auto) { if (true) return 42; else return A{}.g(); } auto main()->int { f(123); } however if we rename A::g as a conversion function: auto f(auto); template<typename = int> struct A { operator auto() { return f(0); } }; auto f(auto) { if (true) return 42; else return static_cast<int>(A{}); } auto main()->int { f(123); } it fails with the error: <source>: In instantiation of 'A< <template-parameter-1-1> >::operator auto() [with <template-parameter-1-1> = int]': <source>:14:36: required from here <source>:6:17: error: use of 'auto f(auto:1) [with auto:1 = int]' before deduction of 'auto' 6 | return f(0); | ~^~~ <source>: In function 'auto f(auto:1)': <source>:14:16: error: invalid 'static_cast' from type 'A<int>' to type 'int' 14 | return static_cast<int>(A{}); | ^~~~~~~~~~~~~~~~~~~~~ ASM generation compiler returned: 1