From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6E1783858D1E for ; Tue, 29 Nov 2022 20:03:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6E1783858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669752207; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4kxxlTV2GLRdbmBbj22b+XjJuB2Ua1uxTq8M6VtZj5I=; b=BCVyQbfknQOcvQyHWwX/VUkKad9Mw2GUZJYDprAFbgHN9Y23BEgHee8KPiU/lXAGgMVMIE Fl0WtpBtTD2jz9Q4AnclJ6ao2mQF5DfnR8ZFjIlb1N0F0LzpGkefd5V6h2REU/9dN5F8ty vySJxOLDlVPKrcSZBxMH0sI+xEvur6k= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-651-7FEh3U10N-a-6pBOyLZE6Q-1; Tue, 29 Nov 2022 15:03:26 -0500 X-MC-Unique: 7FEh3U10N-a-6pBOyLZE6Q-1 Received: by mail-qv1-f71.google.com with SMTP id b2-20020a0cfe62000000b004bbfb15297dso21548464qvv.19 for ; Tue, 29 Nov 2022 12:03:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4kxxlTV2GLRdbmBbj22b+XjJuB2Ua1uxTq8M6VtZj5I=; b=inWBI2e3wHTke573gopSycuD5tahEWdtqopocf7BqKwmYHIwJCvQr2XjCZO5ezrKNK hMD1LRB2NDZ9KlfCIniZs7bYTe8cG/41pLCIlunD6JPXoP5re2VJmUFX7SwKL74eYPjU vo4vT7PCVMKt9MQhHYQfg+Da+Uwm5eytLGIZhwd03BsheB/7N6RbDuRWVlV653G2qkH1 Q531U/dRVkX0l3knwKC/VWGeuNbGfeSzGaGcYbBA9B2zEkkWqugcsNt3JtAmxiB9fs2i H0u98z0dlpYqK7IaVGdnA4nTjmeul3KFDsqgd3vvgYg8mGahWx+6HSBm6KOmQpZQJ9IO zSkA== X-Gm-Message-State: ANoB5pkq6zS12K7upjvM0ZID19VijOfvM3vn4UqEKqU0HKQOrXj4ZeVY Nn80aXXe96GLfugG4f4wepKxOm4zbqq/tWBMXHH8Oib1N+V0fIDWbMhkWAGrxH5XcgxY09GkUW2 W6CPycC3//Gd+y/4DGZmBjZhyfFuX9Irw7864bBpKqwm69XEthYwJg1jt5alnPJJqpVs= X-Received: by 2002:a37:b401:0:b0:6fa:2aef:51ff with SMTP id d1-20020a37b401000000b006fa2aef51ffmr32233808qkf.270.1669752205041; Tue, 29 Nov 2022 12:03:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf5kHxtoyI5+AdTgATASJyhGKC8K9sTEJ8F5OZtJNygtodVSdCcXfHqQEROV9ZpZdwKVm/pSLQ== X-Received: by 2002:a37:b401:0:b0:6fa:2aef:51ff with SMTP id d1-20020a37b401000000b006fa2aef51ffmr32233774qkf.270.1669752204682; Tue, 29 Nov 2022 12:03:24 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id n1-20020a05620a294100b006fa16fe93bbsm11366510qkp.15.2022.11.29.12.03.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 12:03:23 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: ICE with <=> of incompatible pointers [PR107542] Date: Tue, 29 Nov 2022 15:03:22 -0500 Message-Id: <20221129200322.1544250-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc0.49.g083e01275b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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? 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 + +template +concept same_as = __is_same(T, U); + +template +concept Ord = requires(const Lhs& lhs, const 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. -- 2.39.0.rc0.49.g083e01275b