public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: ICE with <=> of incompatible pointers [PR107542]
Date: Tue, 29 Nov 2022 16:16:15 -0500	[thread overview]
Message-ID: <325ad7e5-d814-07c2-e819-34c089fe19c5@redhat.com> (raw)
In-Reply-To: <20221129200322.1544250-1-ppalka@redhat.com>

On 11/29/22 15:03, Patrick Palka wrote:
> In a SFINAE context composite_pointer_type returns error_mark_node if
> the given pointer types are incompatible, but the SPACESHIP_EXPR case of
> cp_build_binary_op wasn't prepared to handle error_mark_node, which led
> to an ICE (from spaceship_comp_cat) for the below testcase where we form
> a <=> with incompatible pointer operands.
> 
> (In a non-SFINAE context composite_pointer_type issues a permerror and
> returns cv void* in this case, so no ICE.)
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/12?

OK.

> 	PR c++/107542
> 
> gcc/cp/ChangeLog:
> 
> 	* typeck.cc (cp_build_binary_op): Handle result_type being
> 	error_mark_node in the SPACESHIP_EXPR case.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/spaceship-sfinae2.C: New test.
> ---
>   gcc/cp/typeck.cc                              |  5 ++--
>   .../g++.dg/cpp2a/spaceship-sfinae2.C          | 29 +++++++++++++++++++
>   2 files changed, 32 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C
> 
> diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc
> index f0e7452f3a0..10b7ed020f7 100644
> --- a/gcc/cp/typeck.cc
> +++ b/gcc/cp/typeck.cc
> @@ -6215,8 +6215,9 @@ cp_build_binary_op (const op_location_t &location,
>         tree_code orig_code0 = TREE_CODE (orig_type0);
>         tree orig_type1 = TREE_TYPE (orig_op1);
>         tree_code orig_code1 = TREE_CODE (orig_type1);
> -      if (!result_type)
> -	/* Nope.  */;
> +      if (!result_type || result_type == error_mark_node)
> +	/* Nope.  */
> +	result_type = NULL_TREE;
>         else if ((orig_code0 == BOOLEAN_TYPE) != (orig_code1 == BOOLEAN_TYPE))
>   	/* "If one of the operands is of type bool and the other is not, the
>   	   program is ill-formed."  */
> diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C
> new file mode 100644
> index 00000000000..52ff038b36f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C
> @@ -0,0 +1,29 @@
> +// PR c++/107542
> +// { dg-do compile { target c++20 } }
> +
> +#include <compare>
> +
> +template<class T, class U>
> +concept same_as = __is_same(T, U);
> +
> +template<class Lhs, class Rhs>
> +concept Ord = requires(const Lhs& lhs, const Rhs& rhs) {
> +  { lhs <=> rhs } -> same_as<std::strong_ordering>;
> +};
> +
> +static_assert(Ord<int*, int*>);  // Works.
> +static_assert(!Ord<int*, char*>); // ICE.
> +
> +template<class T>
> +struct S {
> +  T* p;
> +};
> +
> +template<class T, class U>
> +  requires(Ord<const T*, const U*>)
> +constexpr inline auto operator<=>(const S<T>& l, const S<U>& r) noexcept {
> +  return l.p <=> r.p;
> +}
> +
> +static_assert(Ord<S<int>, S<int>>);   // Works.
> +static_assert(!Ord<S<int>, S<char>>); // ICE.


      reply	other threads:[~2022-11-29 21:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 20:03 Patrick Palka
2022-11-29 21:16 ` Jason Merrill [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=325ad7e5-d814-07c2-e819-34c089fe19c5@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).