https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103333
Bug ID: 103333 Summary: [accepts-invalid] function template argument deduction for incompatible 'transformed A' / 'deduced A' pair Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: davveston at gmail dot com Target Milestone: --- The following program is accepted by GCC but rejected by Clang/MSVC (-std=c++20): --- #include <type_traits> template<typename T, bool b> struct S{ S() = default; template<bool sfinae = true, typename = std::enable_if_t<sfinae && !std::is_const<T>::value>> operator S<T const, b>() { return S<T const, b>{}; } }; template<typename T, bool b1, bool b2> void f(S<const std::type_identity_t<T>, b1>, // ^- T in non-deduced context for func-param #1 S<T, b2>) // ^- T deduced from here {} int main() { S<int, true> s1{}; S<int, false> s2{}; f(s1, s2); } --- The program is ill-formed as function template argument deduction ([temp.deduct.call]) for the first argument resolves in a mismatched deduced A vs. transformed A that is S<const int, true> and S<int, true>, respectively, and none of the three special cases of [temp.deduct.call]/4 allows this mismatch. [temp.arg.explicit]/7 allows a function argument to be converted to the type of the corresponding function parameter, but only if the parameter type contains to template arguments that participate in template argument deduction [from that function argument]. This does not apply here, as the non-type template parameter 'b1' participates in template argument deduction for the call. --- https://timsong-cpp.github.io/cppwp/n4861/temp.deduct.call#4 https://timsong-cpp.github.io/cppwp/n4861/temp.arg.explicit#7