]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: mark_single_function and SFINAE [PR108282]
authorPatrick Palka <ppalka@redhat.com>
Wed, 4 Jan 2023 19:12:25 +0000 (14:12 -0500)
committerPatrick Palka <ppalka@redhat.com>
Wed, 4 Jan 2023 19:14:33 +0000 (14:14 -0500)
We typically ignore mark_used failure when in a non-SFINAE context for
sake of better error recovery.  But in mark_single_function we're
instead ignoring mark_used failure in a SFINAE context, which ends up
causing the second static_assert here to incorrectly fail.

PR c++/108282

gcc/cp/ChangeLog:

* decl2.cc (mark_single_function): Ignore mark_used failure
only in a non-SFINAE context rather than in a SFINAE one.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-requires34.C: New test.

(cherry picked from commit 238e292cf5d822f3bd12d9b58eb04cf377758b2a)

gcc/cp/decl2.cc
gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C [new file with mode: 0644]

index d7e9980ff1e540b3e20b5e3b541eb24e9608550a..37985a37df67e70149e852f0e157e953ab4d9c5e 100644 (file)
@@ -5779,7 +5779,7 @@ mark_single_function (tree expr, tsubst_flags_t complain)
 
   if (is_overloaded_fn (expr) == 1
       && !mark_used (expr, complain)
-      && (complain & tf_error))
+      && !(complain & tf_error))
     return false;
   return true;
 }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires34.C
new file mode 100644 (file)
index 0000000..5bbd62f
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/108282
+// { dg-do compile { target c++20 } }
+
+template<class T>
+concept TEST = requires { T::TT; };
+
+struct C { };
+
+template<class AT>
+struct B {
+  static void TT() requires TEST<AT>;
+};
+
+int main() {
+  static_assert( !TEST<C> );
+  static_assert( !TEST<B<C>> );
+
+  B<C>::TT();  // { dg-error "no match" }
+}