GCC 4.9.0 rejects the following code: struct F { template<class T> operator const T&() { static T t; return t; } }; int main() { F f; int i = f; // error: cannot convert 'F' to 'int' in initialization } As explained in the defects report (http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#976) this used to be invalid but after the corrections in 14.8.2.3 [temp.deduct.conv] paragraphs 1-3 the above code should compile.
Clang also rejects the code.
Clang accepts the code since at least as far back as 3.0.0.
*** Bug 63217 has been marked as a duplicate of this bug. ***
*** Bug 107771 has been marked as a duplicate of this bug. ***
The trunk branch has been updated by Nathan Sidwell <nathan@gcc.gnu.org>: https://gcc.gnu.org/g:80f075b410125bddb31459428760645baba1a69f commit r14-1689-g80f075b410125bddb31459428760645baba1a69f Author: Nathan Sidwell <nathan@acm.org> Date: Sat Jun 10 12:42:17 2023 -0400 c++: Adjust conversion deduction [PR61663][DR976] Drop the return type's reference before doing cvqual and related decays. gcc/cp/ PR c++/61663 * pt.cc (maybe_adjust_types_for_deduction): Implement DR976. gcc/testsuite/ * g++.dg/template/pr61663.C: New.