From patchwork Tue Mar 14 16:41:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 66383 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 536783858418 for ; Tue, 14 Mar 2023 16:42:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 536783858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678812146; bh=vILeZ1/eqZvtQ0qPsHaoUgcg8q8MBjGpbQUuCORPlao=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=F+M4FhqZUxcPxx/BCreahi6RlHGqbpUI/SqEdNIAosvYyKC5uKMCGotUMSNxrOxs2 qSAse7GOJju1EOyfu1Ufg2zR5rbkwFl7tIQ74AwY4LyrnQPmGUqi1yI0ZeUUF7zAJ4 6X6x4P+DklKHAmT8chVyRIZSfSwkBz9P7+P9Fdf0= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 55DE73858C33 for ; Tue, 14 Mar 2023 16:41:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 55DE73858C33 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-qxk9GL1uPhuG0pvVoENn7A-1; Tue, 14 Mar 2023 12:41:50 -0400 X-MC-Unique: qxk9GL1uPhuG0pvVoENn7A-1 Received: by mail-qk1-f200.google.com with SMTP id u6-20020a05620a120600b00745721af155so4048695qkj.10 for ; Tue, 14 Mar 2023 09:41:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678812109; 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=vILeZ1/eqZvtQ0qPsHaoUgcg8q8MBjGpbQUuCORPlao=; b=m/GPsOMpCi8lF35U+jnzjdwjPlXQii8iYEVr8gT1JDSOT0SbhTjmETh39Pzzuq/fCr xjgPeP13lS/lVdRTN4M7SgsoSrIdabxlN07voW6h6v6hILChynvJmPukRAdlvgLrgj3Z SpVK01sKz6Wa4j8hBTadePNj2fYxCdBVSquJiJlKDk1EMCLbuSRXrP5uN4p5BG1cPfJx BmeoiRCCJ5T0Sf5048L7nCQUrQ9PqB8nOR9JnvmQtq5A1TRn8Anz/fTKqOUzs+tXVjmf r518thsoXe4vtr8v20CojGh5OKUZqFfkIEZUZN9KkRyAG+E3Adq/3hlFAMZ8Sdy70bds 4Nuw== X-Gm-Message-State: AO0yUKW8XnRY9TiCCJNoALdMrTl+OyTNBhcuX6i63qcA0Q3Ov1OAAZRZ SOLaI9Hrf4MQBHJRTJh99QjBSsuOBsD8aNXSskSH9Prr0jVkFl1uBkJe0pZU89J7kHx7lrW7m4/ MpWd11Z6/ZFc3x8l4jAdnFVAJoandtG3zV6Ps7aerMFtpNLnk25d3pmUWu9koQwhkQYFQDD6EFJ g= X-Received: by 2002:ac8:7c4e:0:b0:3b9:c352:640e with SMTP id o14-20020ac87c4e000000b003b9c352640emr72389928qtv.46.1678812108866; Tue, 14 Mar 2023 09:41:48 -0700 (PDT) X-Google-Smtp-Source: AK7set9MCnKSS04LjO1oJCAjLU5y9Vpy9Z1XFrREWWhwMZM5+jdG/6gu2+IhWPO3kSowcjqaFaVGSw== X-Received: by 2002:ac8:7c4e:0:b0:3b9:c352:640e with SMTP id o14-20020ac87c4e000000b003b9c352640emr72389854qtv.46.1678812108288; Tue, 14 Mar 2023 09:41:48 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id a20-20020aed2794000000b003b9a573aec6sm2089207qtd.70.2023.03.14.09.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 09:41:47 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: constrained template friend class matching [PR96830] Date: Tue, 14 Mar 2023 12:41:45 -0400 Message-Id: <20230314164146.1470993-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 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: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Here when instantiating a constrained template friend naming an already declared class template, we erroneously pass the existing template's constraints instead of the friend declaration's constraints to redeclare_class_template, which causes the constraint comparison check therein to always be vacuously true, and we fail to diagnose legitimate constraint mismatches. Bootstrapped and regtested on x86_64-pc-linxu-gnu, does this look OK for trunk/12? PR c++/96830 gcc/cp/ChangeLog: * pt.cc (redeclare_class_template): Add missing "of" in constraint mismatch diagnostic. (tsubst_friend_class): For an already declared class template, substitute and pass the friend declaration's constraints to redeclare_class_template instead of passing the existing template's constraints. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-friend14.C: New test. --- gcc/cp/pt.cc | 8 ++++-- .../g++.dg/cpp2a/concepts-friend14.C | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend14.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 85136df1730..053cc52b285 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -6377,7 +6377,7 @@ redeclare_class_template (tree type, tree parms, tree cons) if (!cp_tree_equal (req1, req2)) { auto_diagnostic_group d; - error_at (input_location, "redeclaration %q#D with different " + error_at (input_location, "redeclaration of %q#D with different " "constraints", tmpl); inform (DECL_SOURCE_LOCATION (tmpl), "original declaration appeared here"); @@ -11503,7 +11503,11 @@ tsubst_friend_class (tree friend_tmpl, tree args) tf_warning_or_error); location_t saved_input_location = input_location; input_location = DECL_SOURCE_LOCATION (friend_tmpl); - tree cons = get_constraints (tmpl); + tree cons = get_constraints (friend_tmpl); + ++processing_template_decl; + cons = tsubst_constraint_info (cons, args, tf_warning_or_error, + DECL_FRIEND_CONTEXT (friend_tmpl)); + --processing_template_decl; redeclare_class_template (TREE_TYPE (tmpl), parms, cons); input_location = saved_input_location; } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend14.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend14.C new file mode 100644 index 00000000000..f46c7e4bdfb --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend14.C @@ -0,0 +1,26 @@ +// PR c++/96830 +// { dg-do compile { target c++20 } } + +template requires true +struct A { + template friend struct A; // { dg-error "different constraints" } + template requires (!!true) friend struct A; // { dg-error "different constraints" } +}; + +template +struct B { + template requires true friend struct A; + template requires true friend struct B; // { dg-error "different constraints" } +}; + +template concept C = true; + +template +struct D { + template friend struct D; // { dg-error "different constraints" } + template friend struct D; +}; + +template struct A; +template struct B; +template struct D;