c++: missing SFINAE with pointer subtraction [PR78173]
authorPatrick Palka <ppalka@redhat.com>
Fri, 11 Dec 2020 14:40:58 +0000 (09:40 -0500)
committerPatrick Palka <ppalka@redhat.com>
Fri, 11 Dec 2020 14:40:58 +0000 (09:40 -0500)
This fixes a missed SFINAE when subtracting pointers to an incomplete
type.

gcc/cp/ChangeLog:

PR c++/78173
* typeck.c (pointer_diff): Use complete_type_or_maybe_complain
instead of complete_type_or_else.

gcc/testsuite/ChangeLog:

PR c++/78173
* g++.dg/cpp2a/concepts-pr78173.C: New test.

gcc/cp/typeck.c
gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C [new file with mode: 0644]

index afbb8ef02e6e894fbdce72bd395dd533a59d88e0..a6505814c5304a29bcc1ad2d93d5c105f1da4955 100644 (file)
@@ -5984,7 +5984,7 @@ pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
   tree restype = ptrdiff_type_node;
   tree target_type = TREE_TYPE (ptrtype);
 
-  if (!complete_type_or_else (target_type, NULL_TREE))
+  if (!complete_type_or_maybe_complain (target_type, NULL_TREE, complain))
     return error_mark_node;
 
   if (VOID_TYPE_P (target_type))
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C
new file mode 100644 (file)
index 0000000..50f561a
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/78173
+// { dg-do compile { target c++20 } }
+
+template <class T>
+concept CanDifference = requires(T x, T y) {
+    x - y;
+};
+
+static_assert(!CanDifference<void*>);