From patchwork Thu Apr 13 18:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 83065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1254489vqo; Thu, 13 Apr 2023 12:01:16 -0700 (PDT) X-Google-Smtp-Source: AKy350aTnCI2V6xwcbIrNZityhFvYF701W5uft7r+aRGT97YsMse9atTh6Ug3ViPeHphoZmJmB8c X-Received: by 2002:a17:906:7d8f:b0:94a:85d6:4f75 with SMTP id v15-20020a1709067d8f00b0094a85d64f75mr4449038ejo.77.1681412476288; Thu, 13 Apr 2023 12:01:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681412476; cv=none; d=google.com; s=arc-20160816; b=YOScWEIBMBd5zAzK0XdDnBPv1NGNDAVMZEKSNmCplAVr68etr4yRBNcT+UAv29pvDg VADSiGM1NIpwMBc4EPFyrlJQI3RD6BQgt3vfA4ZQXUOsNs5egTLhO5kER9zWU+LIgeoW fr39oeg0dgv8uoU8lIfGIFli/x3mCNr06MkdKu99MPv2glYkFBmtBeAH1m1vI+pc17nZ DHqI8aEgHmTMd2z9C3CyExKdurmlTDoGn1xBM6UiJR3js4RCPISVCLiFrhtHE36hada0 mFQCzhoArTToYgoFOKEr6iqLySUtglyng+Ullsu0arqeAXIWIoUX3XKsW2PHKpmnDcCa ulBw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=3vZ/NZ+H7DTZ0TE0n0MU/OaPjMoEu94/EhNRSkjfrU0=; b=lrNav05O/hUxT6xW88zQDLwdefIIsF09sKnXB/jSdSPHRXPUOPsN+E5GYJYbBnJ5AB UKAXjscs+0PaRo8RJOt1/qK1bosMv1KgawtE3+tEh/jTPllWh6abYmDtuUMRYp9Ejcvx WkrcGU99xhsOeyfgNlBvq2dJP5IN/maQ9MR8gcpUhSr41w9AJugnymtYpYk+HbbcMVzn Y7QeiCLbw+G8CETjzgwLl0m6s5u0ZRyN1l6gKJuoYQaxgjdFpXKpwZuVtY/8cbrWJt5x yQh18UVzh2zG8VFFh96jY1mroSsP5CTbATBLGYsHUg9geWF+jPgJjWtqMccH/m/s88vp t9lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ANnXWRyO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j2-20020a1709062a0200b0094e1026c195si2213881eje.812.2023.04.13.12.01.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 12:01:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ANnXWRyO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 96C663857031 for ; Thu, 13 Apr 2023 19:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96C663857031 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681412440; bh=3vZ/NZ+H7DTZ0TE0n0MU/OaPjMoEu94/EhNRSkjfrU0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ANnXWRyOSSkTtslynB7CM5XDozwe37mgTnTmycGmJ9N7Ncs6JMbVMSgd/v5eOcgmI 3t3JLd80wKJAOz+5Bs5Q8vmKLVZCi1M8Eik0GyNhD2Ye61qXMyDi6zWCN2/2r7MbbL UDIs00c0U+Str/NfuhaBtLlEqYOc6fCBO/RCXYm0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 82A413858D3C for ; Thu, 13 Apr 2023 18:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82A413858D3C 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_256_GCM_SHA384) id us-mta-42-j7CeeK7DOz2NVvJxGCiD8Q-1; Thu, 13 Apr 2023 14:59:28 -0400 X-MC-Unique: j7CeeK7DOz2NVvJxGCiD8Q-1 Received: by mail-qv1-f71.google.com with SMTP id n12-20020a0cbe8c000000b005e79f8d1417so9667339qvi.13 for ; Thu, 13 Apr 2023 11:59:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681412367; x=1684004367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3vZ/NZ+H7DTZ0TE0n0MU/OaPjMoEu94/EhNRSkjfrU0=; b=l5uf549G5f4PzfxAeBiSbAEs48vMnoWa2qspl34yjlnUoQO/XfqL2HIRDTsYPpAFBo boxZj7MWhVebAESqhXCZv4JDfLPAtVnELXKtlA37qnl3CCXnjnWdmHogqowyHLHwMJBM Y29tVGzd/afsZDTYz42J0VqckFBuWkRNickCtPPrJBoLafkZfDTX9YqGUKV7lGkWgZeT WqFKYvwVFzEkW0lx7psv1vt9Nuil9oVG3AlLFD5M3XZAdhNV1wYSY4ntRyFTkZZx2wL8 3zwpetfmm0v6B2Icj/zdWqyvolIskqnpmjCqaeAfo6038418nUrXstbatBZyaIysFBNj HJPw== X-Gm-Message-State: AAQBX9e8FLCepfuZsZ15aoUHd7+TyBFxv9h1ksoyZpnZB+L/pk6bar5f jgdXFUMG1G8pLCPpHyKSGTkHebEAuTh0wI4rBOcQgdQdWL4vq9Vu9rf8pMqH6ai76opPk8f2CxS 8fTk2VMtRbxZswwd3bNNtBI3Xi6zf8pDWOSxgW6HbD0jk6dW9W75usreQtlRafQknzufhZayFIQ == X-Received: by 2002:a05:622a:1a97:b0:3e6:38cf:fc93 with SMTP id s23-20020a05622a1a9700b003e638cffc93mr4839677qtc.19.1681412367235; Thu, 13 Apr 2023 11:59:27 -0700 (PDT) X-Received: by 2002:a05:622a:1a97:b0:3e6:38cf:fc93 with SMTP id s23-20020a05622a1a9700b003e638cffc93mr4839653qtc.19.1681412366808; Thu, 13 Apr 2023 11:59:26 -0700 (PDT) Received: from jason.com ([66.31.49.15]) by smtp.gmail.com with ESMTPSA id f13-20020ac8068d000000b003e3918f350dsm686385qth.25.2023.04.13.11.59.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:59:26 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++: make trait of incomplete type a permerror [PR109277] Date: Thu, 13 Apr 2023 14:59:21 -0400 Message-Id: <20230413185921.2201433-2-jason@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230413185921.2201433-1-jason@redhat.com> References: <20230413185921.2201433-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.8 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763088768416452846?= X-GMAIL-MSGID: =?utf-8?q?1763088768416452846?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- An incomplete type argument to several traits is specified to be undefined behavior in the library; since it's a compile-time property, we diagnose it. But apparently some code was relying on the previous behavior of not diagnosing. So let's make it a permerror. The assert in cxx_incomplete_type_diagnostic didn't like that, and I don't see the point of having the assert, so let's just remove it. PR c++/109277 gcc/cp/ChangeLog: * semantics.cc (check_trait_type): Handle incomplete type directly. * typeck2.cc (cxx_incomplete_type_diagnostic): Remove assert. gcc/testsuite/ChangeLog: * g++.dg/ext/is_convertible5.C: New test. --- gcc/cp/semantics.cc | 7 ++++++- gcc/cp/typeck2.cc | 4 ---- gcc/testsuite/g++.dg/ext/is_convertible5.C | 7 +++++++ 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_convertible5.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 99a76e3ed65..45e0b0e81d3 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12107,7 +12107,12 @@ check_trait_type (tree type, int kind = 1) if (VOID_TYPE_P (type)) return true; - return !!complete_type_or_else (strip_array_types (type), NULL_TREE); + type = complete_type (strip_array_types (type)); + if (!COMPLETE_TYPE_P (type) + && cxx_incomplete_type_diagnostic (NULL_TREE, type, DK_PERMERROR) + && !flag_permissive) + return false; + return true; } /* Process a trait expression. */ diff --git a/gcc/cp/typeck2.cc b/gcc/cp/typeck2.cc index 76a7a7f6b98..bf03967a71f 100644 --- a/gcc/cp/typeck2.cc +++ b/gcc/cp/typeck2.cc @@ -298,10 +298,6 @@ cxx_incomplete_type_diagnostic (location_t loc, const_tree value, { bool is_decl = false, complained = false; - gcc_assert (diag_kind == DK_WARNING - || diag_kind == DK_PEDWARN - || diag_kind == DK_ERROR); - /* Avoid duplicate error message. */ if (TREE_CODE (type) == ERROR_MARK) return false; diff --git a/gcc/testsuite/g++.dg/ext/is_convertible5.C b/gcc/testsuite/g++.dg/ext/is_convertible5.C new file mode 100644 index 00000000000..ab9be05afea --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_convertible5.C @@ -0,0 +1,7 @@ +// PR c++/109277 +// { dg-do compile { target c++11 } } +// { dg-options -fpermissive } + +struct a; +struct b{}; +static_assert (!__is_convertible (a, b), ""); // { dg-warning "incomplete" }