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.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 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=1681412369; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3vZ/NZ+H7DTZ0TE0n0MU/OaPjMoEu94/EhNRSkjfrU0=; b=X4tYRATkMloQKmpSmKeNz6+t3vkf+PJkR36bTeSnuH44eZDX4STgpM5j7yz281znHkG+r/ U+L2XIMWIxmoGi6oWyqJdCLJwIXJeIWQddpQVmjLNdcI4w8eSlZAC32RvaKHKubES48KsH qtlu0ZqVAogQtwVnDBvxJ4EiW0p0B0s= 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-Google-Smtp-Source: AKy350ZdS/80VToizwgPV6OtiNVwyfOSup9CuY0ls2TFyYZxFtb/MPEZYu/KisPVNHj38lbaOWpFGg== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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" } -- 2.31.1