From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id AB1093858D1E; Mon, 19 Dec 2022 16:54:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB1093858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671468869; bh=/tHOCpPBdI3l/3yeB7qgbXGt7QgL6KGbRvnsNdwG5L8=; h=From:To:Subject:Date:From; b=liTyqjWv35Ye41RBYrEmO9QacdgUGUo+WTjv716Ubd4J1rP1jRDpfoDyVaxOB0j86 FOEnqGqi0t/jnpprABI260e3qEaaoRCQdD/buvYphXLYIs4IQuqwng+YOVm4GjFRHC S+p6TjeOra0yPQWAuct46IWH39lvEPxsytH9laBc= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8994] c++: ICE with <=> of incompatible pointers [PR107542] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 0e345504ec9349d9a3bf826c3e16b7e973739485 X-Git-Newrev: 37595f8354e3e48e4a1a94537f3d1ae095ed75df Message-Id: <20221219165429.AB1093858D1E@sourceware.org> Date: Mon, 19 Dec 2022 16:54:29 +0000 (GMT) List-Id: https://gcc.gnu.org/g:37595f8354e3e48e4a1a94537f3d1ae095ed75df commit r12-8994-g37595f8354e3e48e4a1a94537f3d1ae095ed75df Author: Patrick Palka Date: Tue Nov 29 19:25:37 2022 -0500 c++: ICE with <=> of incompatible pointers [PR107542] 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 for this error_mark_node result, which led to an ICE (from spaceship_comp_cat) for the below testcase. (In a non-SFINAE context composite_pointer_type issues a permerror and returns cv void* in this case, so this ICE seems specific to SFINAE.) PR c++/107542 gcc/cp/ChangeLog: * typeck.cc (cp_build_binary_op): In the SPACESHIP_EXPR case, handle an error_mark_node result type. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/spaceship-sfinae2.C: New test. (cherry picked from commit 000e9863120cbc75a0f8d497264519974c97669f) Diff: --- gcc/cp/typeck.cc | 5 +++-- gcc/testsuite/g++.dg/cpp2a/spaceship-sfinae2.C | 29 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index b2ffde34dde..c36508b8cc5 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -5921,8 +5921,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..7105a2c7f2a --- /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 + +template +concept same_as = __is_same(T, U); + +template +concept Ord = requires(Lhs lhs, Rhs rhs) { + { lhs <=> rhs } -> same_as; +}; + +static_assert(Ord); // Works. +static_assert(!Ord); // ICE. + +template +struct S { + T* p; +}; + +template + requires(Ord) +constexpr inline auto operator<=>(const S& l, const S& r) noexcept { + return l.p <=> r.p; +} + +static_assert(Ord, S>); // Works. +static_assert(!Ord, S>); // ICE.