diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 976330cd23f8ce097f517a86b535e9f45f4a251a..24f93dd983ca08017eb39f8b6b845aa257629d7c 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -2588,6 +2588,14 @@ add_conv_candidate (struct z_candidate **candidates, tree fn, tree obj, if (*candidates && (*candidates)->fn == totype) return NULL; + if (!constraints_satisfied_p (fn)) + { + reason = constraint_failure (); + viable = 0; + return add_candidate (candidates, fn, obj, arglist, len, convs, + access_path, conversion_path, viable, reason, flags); + } + for (i = 0; i < len; ++i) { tree arg, argtype, convert_type = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate1.C new file mode 100644 index 0000000000000000000000000000000000000000..e8481a316568611be7b207b0e97e319e7c1515c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate1.C @@ -0,0 +1,12 @@ +// PR c++/110535 +// { dg-do compile { target c++20 } } + +using F = int(int); + +template<bool B> +struct A { + operator F*() requires B; +}; + +int i = A<true>{}(0); // OK +int j = A<false>{}(0); // { dg-error "no match" } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate2.C new file mode 100644 index 0000000000000000000000000000000000000000..8bf8364beb721760b0c69a993e8f48e2b05b3aaa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-surrogate2.C @@ -0,0 +1,14 @@ +// PR c++/110535 +// { dg-do compile { target c++20 } } + +using F = int(int); +using G = long(int); + +template<bool B> +struct A { + operator F&() requires B; + operator G&() requires (!B); +}; + +int i = A<true>{}(0); // { dg-bogus "ambiguous" } +int j = A<false>{}(0); // { dg-bogus "ambiguous" }