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: 69729 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1863466wrd; Tue, 14 Mar 2023 09:43:07 -0700 (PDT) X-Google-Smtp-Source: AK7set9i026L7TYFaxt9yxny8S9UGrMsvJfWaGkOTY4j1ZxwWoKZlSjUwnLH4UaCPak0hujSvxrX X-Received: by 2002:a17:907:a649:b0:8f2:62a9:6159 with SMTP id vu9-20020a170907a64900b008f262a96159mr3715070ejc.2.1678812187596; Tue, 14 Mar 2023 09:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678812187; cv=none; d=google.com; s=arc-20160816; b=W7wSS6nV3OgDJ3azyEdbFuXXtJEGB0wcsT4C3TnO1YNfwbu8/9Q3HZUBakSnCy3jyn iMK+F8OlaEpjot/DW0pCb/OHdlc3Yo6FMoBvE8hltQyvVyofAydB+KKKh85DCRFMSkiL p4p6YGiRrz1Cty7qHjLDZiuUmrzj/qwZ3m/l9x9gjGMWiYfowbrcjZpu0X1me0BJ85cB IL2169Gh5we3yL9bkHWhRPEnz/uZzZQITzLlwa4zlhL5V957FaQRiZB8oAzxnyCEJiY+ +lSl6vFbYJLZjHzf6mR0HmGjX375nPofIpgxPVPgla6WeYX+kjP2VEk2CP+J5uanvjWa mvPA== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=vILeZ1/eqZvtQ0qPsHaoUgcg8q8MBjGpbQUuCORPlao=; b=X616Ahn/soB+zlXBCO+l733i1nvV1LOZH+ROm2zn/Z5STh80CJxHq4IhBPNu9+4Lsg NiEn+1CZyMuSFszaGjYJJZQJriGxKrTjhwR/jy+3l3CT7NNx+ds++w+XYjKMCZyQ5Ns0 RQHQfLoHRnb/QVAUaFtTRCt9ae4R0lt0MKQ5UtxPnwdNsKSYqEDXx1y2nNIJa7i2u/pN RxPu/9q+YhtBkTBRuP6xmzp7Q0FA45an3HmtMoCPRZn4WtG2n1q3ZaDd4sEBbyou0JSf 6/4awv844Afxr4S63GP/J5jdjo2Aw28v5gB89SCXR0bPo35Nevcb0vx9NV5OP6TFk/tg qZqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cODiAibD; 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 kj28-20020a170907765c00b00927ad25b660si3238859ejc.356.2023.03.14.09.43.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 09:43:07 -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=cODiAibD; 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 7C0A7385E004 for ; Tue, 14 Mar 2023 16:42:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C0A7385E004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678812161; 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=cODiAibDM9EMQUypJZuwY0Wjv5xKuU56FUgVb2REs8wUIIepXBFt/aMq4xmPsu/Ta dLcVWqO0pzPrYTtB6pGfrKYwXkf8snjdAKIl9o8KOhrmP/D4ykbVGLKuTupmPnvy5L 2AYBIHhLGmoTHE7M+xGJXj7G2crgTCkxxu3zdhEg= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760362168208114251?= X-GMAIL-MSGID: =?utf-8?q?1760362168208114251?= 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;