public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: missing SFINAE with pointer subtraction [PR78173]
@ 2020-12-11  5:44 Patrick Palka
  2020-12-11  6:39 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2020-12-11  5:44 UTC (permalink / raw)
  To: gcc-patches

This fixes a missed SFINAE when subtracting pointers to an incomplete
type.

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk?

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                               | 2 +-
 gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index dd84674a5e6..c41457bcce8 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5985,7 +5985,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
index 00000000000..50f561abcce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C
@@ -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*>);
-- 
2.29.2.540.g3cf59784d4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: missing SFINAE with pointer subtraction [PR78173]
  2020-12-11  5:44 [PATCH] c++: missing SFINAE with pointer subtraction [PR78173] Patrick Palka
@ 2020-12-11  6:39 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-12-11  6:39 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches List

Ok.

On Fri, Dec 11, 2020, 12:45 AM Patrick Palka <ppalka@redhat.com> wrote:

> This fixes a missed SFINAE when subtracting pointers to an incomplete
> type.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk?
>
> 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                               | 2 +-
>  gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C | 9 +++++++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C
>
> diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
> index dd84674a5e6..c41457bcce8 100644
> --- a/gcc/cp/typeck.c
> +++ b/gcc/cp/typeck.c
> @@ -5985,7 +5985,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
> index 00000000000..50f561abcce
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr78173.C
> @@ -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*>);
> --
> 2.29.2.540.g3cf59784d4
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-11  6:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11  5:44 [PATCH] c++: missing SFINAE with pointer subtraction [PR78173] Patrick Palka
2020-12-11  6:39 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).