From patchwork Wed Aug 7 15:09:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1970105 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=OHvTUpEa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WfD9Y5tYCz1yXs for ; Thu, 8 Aug 2024 01:09:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1DE5385B82F for ; Wed, 7 Aug 2024 15:09:35 +0000 (GMT) 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 ESMTP id 780B13858C41 for ; Wed, 7 Aug 2024 15:09:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 780B13858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 780B13858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723043354; cv=none; b=O0G/k/DE/9t+0ZidM8fyrM8I05l8NqZR0fsbSEraL06YtAoOE433BDkaZ0SZ+F+ysSzsDhzca/P9oUqm8Nildx8qiCuZrkUEDdD0P3GPD8vVCvyGFo2UNpgXJpiHNcjeP1o4l+jScyd7qZTlqENVChqiI/zZGlCr0y8UJHFYnN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723043354; c=relaxed/simple; bh=E/sTuFIotp5ohR0y5RtMXi/K9MxjwDKLdjyWKkob6uE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vQROlYKbSZ1ViNFd21dmkWO4nSSQcezF2FDlw9Q9cp5bf+wafHK6IYINfBOEZBEWkgRFCd+Ha2ba2UK1Hpo+lRZ241WrAke+K5hRCABPz2fuq8JiSKgnFqSF+qsMAt+GWQECoUXZkIOx6bQBvtNRnw+ylo6vuGCmDMxeh/WEPnA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723043351; 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=zC4yIA2B5xzPVjD3u0WWKmlRU4SG3e79sdQF118rF74=; b=OHvTUpEaRe7xHc3kBNJkhUftLOXy8HZabNhsLUjj+BWhjOfhI2upshBKoK1zpHAPZFab6M me52y//Q3/mO8oY8Wkg42Rabm4RzndwVm8YmKYn/hLofvqS2OpByFTDArtP7D9sW2AyrgR lWjqFYmO/bApYuoZ86pr/rpImCyUjmU= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-2kUw1bUCNyajT4DWArhZUA-1; Wed, 07 Aug 2024 11:09:09 -0400 X-MC-Unique: 2kUw1bUCNyajT4DWArhZUA-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6b7a50b41a4so165856d6.1 for ; Wed, 07 Aug 2024 08:09:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723043348; x=1723648148; 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=zC4yIA2B5xzPVjD3u0WWKmlRU4SG3e79sdQF118rF74=; b=Pbca5jpCsD+jRetlGX6C473G2OAh+EK8gOL2LMhmfgCelKQ6D0VD/KzmgfrzZfmRfI J9aXGcbWJSZ56QfaHP67zhGpjIlMMUtyl7wBPpk/iiu/SsgPx+rNcH2eEmeUw7dRUnbG MHvv5ATljp+dqmjsojoQmoZTs1U+1wlmhdJXBVHBshgs0U6VF8HNmnpqpqktiuhKk0NH asPtl+36KyuETWQZB0YkYdbREuhk44rGaf8kQ7wmCU/iGw7hLTw3Cb7py8WnZOnQg4SW QrgW2QxxRhC/+kmehx2wSkHU80r4jKYqe7ZJvX4N0QVX24oJPC0xauAXP3q5q0tUkk+5 m5TQ== X-Gm-Message-State: AOJu0YzUm9Z094j2nZTizq1cYJNO56sWYfL0L6YO1HfzTtgpEbRbnaK4 zydUbvtQFlL86DKQsjNVr/pbzyvXSjKS3CbpgCgvxpm8V2SyFc2VhNhWNUIriJ/0Qq56fbiXKWl /m4Z+YFibEWREzGFZZL7CwWFDSr8WqcMICQldiZyvxeloE/GmJO5nNu1oEW3BgbzOXg5ruHaRPc ttjtzxddp2preajLtjcomIdEdUgdJMXk21TqPR X-Received: by 2002:a05:6214:5f0e:b0:6bb:7a04:3408 with SMTP id 6a1803df08f44-6bb9836f7f7mr227308776d6.11.1723043348044; Wed, 07 Aug 2024 08:09:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8CdhFOqzLIv/jFZTsciUGzV364lBZR9D9IN2Dv/BNwj+Ks6CCaDqEbNXGMcBaF3g4L0vM2g== X-Received: by 2002:a05:6214:5f0e:b0:6bb:7a04:3408 with SMTP id 6a1803df08f44-6bb9836f7f7mr227308456d6.11.1723043347621; Wed, 07 Aug 2024 08:09:07 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb9c866ccfsm57014636d6.107.2024.08.07.08.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Aug 2024 08:09:07 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: erroneous partial spec vs primary tmpl [PR116064] Date: Wed, 7 Aug 2024 11:09:00 -0400 Message-ID: <20240807150900.1390001-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.39.g891ee3b9db MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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_H4, RCVD_IN_MSPIKE_WL, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- When a partial specialization is deemed erroneous at parse time, we currently flag the primary template as erroneous instead. Later at instantiation time we check if the primary template is erroneous rather than the selected partial specialization, so at least we're consistent. But it's better not to conflate a partial specialization with the primary template since they're instantiated independenty. This avoids rejecting the instantiation of A in the below testcase. PR c++/116064 gcc/cp/ChangeLog: * error.cc (get_current_template): If the current scope is a partial specialization, return it instead of the primary template. * pt.cc (instantiate_class_template): Pass the partial specialization if any to maybe_diagnose_erroneous_template instead of the primary template. gcc/testsuite/ChangeLog: * g++.dg/template/permissive-error2.C: New test. --- gcc/cp/error.cc | 6 +++++- gcc/cp/pt.cc | 2 +- gcc/testsuite/g++.dg/template/permissive-error2.C | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/permissive-error2.C diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 6c22ff55b46..879e5a115cf 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -173,7 +173,11 @@ get_current_template () { if (scope_chain && in_template_context && !current_instantiation ()) if (tree ti = get_template_info (current_scope ())) - return TI_TEMPLATE (ti); + { + if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (ti)) && TI_PARTIAL_INFO (ti)) + ti = TI_PARTIAL_INFO (ti); + return TI_TEMPLATE (ti); + } return NULL_TREE; } diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 542962b6387..3e55d5c0fea 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -12381,7 +12381,7 @@ instantiate_class_template (tree type) if (! push_tinst_level (type)) return type; - maybe_diagnose_erroneous_template (templ); + maybe_diagnose_erroneous_template (t ? TI_TEMPLATE (t) : templ); int saved_unevaluated_operand = cp_unevaluated_operand; int saved_inhibit_evaluation_warnings = c_inhibit_evaluation_warnings; diff --git a/gcc/testsuite/g++.dg/template/permissive-error2.C b/gcc/testsuite/g++.dg/template/permissive-error2.C new file mode 100644 index 00000000000..692e7c7ac82 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/permissive-error2.C @@ -0,0 +1,15 @@ +// PR c++/116064 +// { dg-additional-options -fpermissive } +// Verify we correctly mark a partial specialization as erroneous +// instead its primary template. + +template +struct A { }; + +template +struct A { // { dg-error "instantiating erroneous template" } + void f(typename A::type); // { dg-warning "does not name a type" } +}; + +A a; // { dg-bogus "" } +A b; // { dg-message "required from here" }