From patchwork Tue Feb 13 16:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1898317 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=LVeRoAa7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4TZ5z65qPcz23hT for ; Wed, 14 Feb 2024 03:15:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B31F2385802A for ; Tue, 13 Feb 2024 16:15:44 +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 ESMTPS id 6F27238582B1 for ; Tue, 13 Feb 2024 16:15:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F27238582B1 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 6F27238582B1 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=1707840923; cv=none; b=PEbgN3uqm3BJPvIP5pXRZW3pwi3RSc8/eITOvhqfZwLu2LWXTQr8IoTCWmpUc0yeEmuwgbPTNXmQKgjvLFICkieBES2/4HyGME1mqAYLuGDu913X298Yq67jc8rbnGBZVrtDxw7kwm23vTf9JzsbAYLSXW3bBUVASfQkIPUV6gA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707840923; c=relaxed/simple; bh=ng426xp/SbfwEuJIfbLzC329OnfZLtmK8f4Y+R30meo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MwtsxVR5n6zPQ49Byse6DS0tak7bdmt4BSSUgjZU7aNpqBRtTAtSi1D5csZJmAVuAJBxRQmac77K1B40S7X/evWTa85AiW/SebtydXFl9HrK4Vey5+EK6TsKaO/GfnKJKJxx0y+5o4Vec0Nix7QSFpu/Lk7XTHbmlcTDZfQj+PA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707840921; 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; bh=csyE6Z+nc1GXO045GVtyndqnllAN83gQ9h/IwEgPhjo=; b=LVeRoAa7QugggsHjF2PmMN5JVbdAC6CiiUpkoA/v8dsDvrlPAm/k3zLsQKjNbtE5VHUBQO mC5HkTO5uLEFRTEqK2Oer7BFjm7zz9lJ2PXdHUHCI7OxJa+B4mvp3ymTE41C+2nPx2gxBx eQgf8rOxI/HWmdoW+qnceWYBm1uRJro= 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-336-kRsgtpWvMKWeyRPUP43Vug-1; Tue, 13 Feb 2024 11:15:19 -0500 X-MC-Unique: kRsgtpWvMKWeyRPUP43Vug-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-68ee3abca37so13687396d6.2 for ; Tue, 13 Feb 2024 08:15:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707840918; x=1708445718; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=csyE6Z+nc1GXO045GVtyndqnllAN83gQ9h/IwEgPhjo=; b=s5RitTl6sV/CpbE5El4L56kq7S6R1efLNQ23S1zQiCh+Xcs0a7KtyIxeXi4onbr2q2 X5aReFTCPalg3MvzZ0sadLV7+UKAE1aEXs6wRn7bBTv7JGoLgswUuwwHfGQNCIi9KsdW GIEJTKWvVw1tkUrLfvJ57ZkKsrzEbd6BzlYTuP+bAhID1S/Dd4kjR0hDzv7USKLaMLCZ KYScixf3Rnww1m7+ir+9bTPyLEtuIhlp6kBiz19bMyfOoyIAl62upayQrKa7iTOFWXi+ HDJqVXKLqLM2mO73FNviLDp28LMnPKRLQWz2O0Z35IWG05sK44A2kXKnwMoGtGGqGpbk cnUg== X-Gm-Message-State: AOJu0YzCX26ZUxxbkIWsIeUAWS62oL6kOp6ZuJYxqqXIhEsuti0zg0c8 Zv9p/ECSK2ZTPhkda2peFQaFNCqHyO1INXPfTrvYUu0i/qUoE19cIFl652LMEyU54ZnzZxpD3Qa 1ngANaT7EkIqXPGdBwZjfgo2Y5I3PltPl123fpL18nbog22+kF5MNM1+WXO2shpvVqOLotSaDc3 BWKcWiPE/XiQSIxBbfoOTN8sB+H6cFBW/QhVI= X-Received: by 2002:a0c:e488:0:b0:68c:c60e:7eba with SMTP id n8-20020a0ce488000000b0068cc60e7ebamr9736863qvl.55.1707840918229; Tue, 13 Feb 2024 08:15:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IErOyCAMxZqiT508b0x0y7tpzWzBuRy7D4sf5KxUSNiWtcKHPn+dvMvmZHMU9AuN2pUkvjU5Q== X-Received: by 2002:a0c:e488:0:b0:68c:c60e:7eba with SMTP id n8-20020a0ce488000000b0068cc60e7ebamr9736840qvl.55.1707840917712; Tue, 13 Feb 2024 08:15:17 -0800 (PST) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id fc13-20020ad44f2d000000b0068c6fe93f45sm1374915qvb.122.2024.02.13.08.15.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 08:15:16 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: variable partial spec redeclaration [PR113612] Date: Tue, 13 Feb 2024 11:13:58 -0500 Message-ID: <20240213161515.834255-1-jason@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.5 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, T_SCC_BODY_TEXT_LINE 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 Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- If register_specialization finds a previous declaration and throws the new one away, we shouldn't still add the new one to DECL_TEMPLATE_SPECIALIZATIONS. PR c++/113612 gcc/cp/ChangeLog: * pt.cc (process_partial_specialization): Return early on redeclaration. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/var-templ85.C: New test. --- gcc/cp/pt.cc | 11 ++++++++--- gcc/testsuite/g++.dg/cpp1y/var-templ85.C | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ85.C base-commit: f29f7f86935e29786bf9f976ec99d7639b381b14 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 9c225c095c8..8bef2f8f6a2 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -5417,9 +5417,14 @@ process_partial_specialization (tree decl) } if (VAR_P (decl)) - /* We didn't register this in check_explicit_specialization so we could - wait until the constraints were set. */ - decl = register_specialization (decl, maintmpl, specargs, false, 0); + { + /* We didn't register this in check_explicit_specialization so we could + wait until the constraints were set. */ + tree reg = register_specialization (decl, maintmpl, specargs, false, 0); + if (reg != decl) + /* Redeclaration. */ + return reg; + } else associate_classtype_constraints (type); diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ85.C b/gcc/testsuite/g++.dg/cpp1y/var-templ85.C new file mode 100644 index 00000000000..33c24e0c284 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ85.C @@ -0,0 +1,6 @@ +// PR c++/113612 +// { dg-do compile { target c++14 } } + +template T t; +template extern T *t; +template T *t = t;