From patchwork Mon Mar 28 13:33:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1610168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ubURSEvK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRtz833gCz9sDX for ; Tue, 29 Mar 2022 00:37:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D47793857C71 for ; Mon, 28 Mar 2022 13:37:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D47793857C71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648474625; bh=rHzK7LiAmskhs7E4lwPtAfrahWp6C2OZlm42PXBWllI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ubURSEvKM7/JaLz5iBR6P372p5xB75GEUEHxDPn0MvzhByBqqliHkjE+B8iDmfl+M WxQ0j3sgH8XAHpZ2Zn9TbaVg4xQktrZUly4rIqWtMS7Djr5JTSegFqRaFvjucIt58M lt+X8McAwZvg4Y5wFf97Yvkw/1V6ta851JIdo8uo= 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 BBDC8385DC06 for ; Mon, 28 Mar 2022 13:33:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBDC8385DC06 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-468-UoGa44PoPlmfqe9WC3RiTg-1; Mon, 28 Mar 2022 09:33:42 -0400 X-MC-Unique: UoGa44PoPlmfqe9WC3RiTg-1 Received: by mail-qv1-f70.google.com with SMTP id g1-20020ad446c1000000b00440c9327221so11335634qvw.6 for ; Mon, 28 Mar 2022 06:33:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=rHzK7LiAmskhs7E4lwPtAfrahWp6C2OZlm42PXBWllI=; b=nsl/v/jueemM+G4rHhFwpS7P0mt5nTVlX8Jx5eHvIAQK6CJ5O11J+xdzvm4PoOQ2in BLCH/aLWVm92nbOaSvjvY6J4ubTsWgQ1X7ZnG7XhiyX+sQw6OdMLErmIvXXHGUzi4WSB IhO+jCdKKDKR3SzJBkKen4b9Xd3HtG+dm/B4mKw0wIU0L0Sy02tKGK84IDuaZh6iaLmM HLea2Xnh98vqB+r44tpYFdPb6EOV+lAA2wqvsg26bvPTE1gFKBNQjTgsmgfMlwajDKAV L/q2R+S6nx3dvZJGK481o/4d1vhnNUp8yiKVAPGiPNLsdLXXn6DjzJ6v8bL/URjhJbuO KsZA== X-Gm-Message-State: AOAM532q8VtLoUvRIgKseg7jsfanTR1XGYb+XALDkiGBwHFWrExHeISM Y4LST89PXQa1KOykyhArb8lUgRi3c11MnRjm8mGzS835MB8rOa6/XMF2eDbeoEn8gLb3/1BbZxD a3MQp0qD52ONU8gRIaoY0mQSinXnL10TXiL5hJJLkx8CcpzYbYIXsfD6xFd3Gmz0T+w== X-Received: by 2002:ac8:5a05:0:b0:2e1:a657:54ce with SMTP id n5-20020ac85a05000000b002e1a65754cemr21645683qta.161.1648474421384; Mon, 28 Mar 2022 06:33:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtb4aOPtXozj0XZMHec7UcYCMcJLqYkLqFB+sEPBdKBMpeTmGvngUAIfwvKRQUMpQPTgudtw== X-Received: by 2002:ac8:5a05:0:b0:2e1:a657:54ce with SMTP id n5-20020ac85a05000000b002e1a65754cemr21645629qta.161.1648474420846; Mon, 28 Mar 2022 06:33:40 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id c10-20020ac87dca000000b002e1db1b7b10sm12509457qte.25.2022.03.28.06.33.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 06:33:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: CTAD and member function references [PR103943] Date: Mon, 28 Mar 2022 09:33:38 -0400 Message-Id: <20220328133338.2584112-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 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, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" More quirks of rewriting member references to dependent references for CTAD. A reference to a member of dependent scope is definitely dependent. And since r11-7044, tsubst_baselink builds a SCOPE_REF, so tsubst_qualified_id should just use it. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/103943 gcc/cp/ChangeLog: * pt.cc (tsubst_qualified_id): Handle getting SCOPE_REF from tsubst_baselink. (instantiation_dependent_scope_ref_p): Check dependent_scope_p. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction109.C: New test. --- gcc/cp/pt.cc | 21 ++++-- .../g++.dg/cpp1z/class-deduction109.C | 64 +++++++++++++++++++ 2 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction109.C base-commit: bc86a86a4f2c057bc0e0be94dcbb8c128ae7f717 prerequisite-patch-id: 09e711b54e7911a4a04bd7808abc1b73ae4482ba prerequisite-patch-id: 566cf0772894d0c6a842b2e0ca62eb1d5ae8ad33 prerequisite-patch-id: b1def7e83e76c1652efb483cb2b67e472d15b720 prerequisite-patch-id: 12973b1310781ff6ce5c9792ea689f0673fc5251 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index edd8bebc1bb..2738c20dafa 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16623,12 +16623,20 @@ tsubst_qualified_id (tree qualified_id, tree args, if (dependent_scope_p (scope)) { - if (is_template) - expr = build_min_nt_loc (loc, TEMPLATE_ID_EXPR, expr, template_args); - tree r = build_qualified_name (NULL_TREE, scope, expr, - QUALIFIED_NAME_IS_TEMPLATE (qualified_id)); - REF_PARENTHESIZED_P (r) = REF_PARENTHESIZED_P (qualified_id); - return r; + if (TREE_CODE (expr) == SCOPE_REF) + /* We built one in tsubst_baselink. */ + gcc_checking_assert (same_type_p (scope, TREE_OPERAND (expr, 0))); + else + { + if (is_template) + expr = build_min_nt_loc (loc, TEMPLATE_ID_EXPR, expr, + template_args); + expr = build_qualified_name (NULL_TREE, scope, expr, + QUALIFIED_NAME_IS_TEMPLATE + (qualified_id)); + } + REF_PARENTHESIZED_P (expr) = REF_PARENTHESIZED_P (qualified_id); + return expr; } if (!BASELINK_P (name) && !DECL_P (expr)) @@ -27367,6 +27375,7 @@ instantiation_dependent_scope_ref_p (tree t) { if (DECL_P (TREE_OPERAND (t, 1)) && CLASS_TYPE_P (TREE_OPERAND (t, 0)) + && !dependent_scope_p (TREE_OPERAND (t, 0)) && !unknown_base_ref_p (t) && accessible_in_template_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1))) diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C new file mode 100644 index 00000000000..e621ebad28a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction109.C @@ -0,0 +1,64 @@ +// PR c++/103943 +// { dg-do compile { target c++17 } } + +template struct F0 { //OK + R(*fun_ptr)(AA...); +}; +template struct F1 { //OK + R(*fun_ptr)(AA...); + F1(R(*fun_ptr)(AA...)) : fun_ptr(fun_ptr) {} +}; +template struct F2 { //OK + R(*fun_ptr)(AA...); + using fun_ptr_t = decltype(fun_ptr); + F2(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template struct F3 { + R(*fun_ptr)(AA...); +// using fun_ptr_t = decltype(fun_ptr); //OK as in F2 + using fun_ptr_t = decltype(F3::fun_ptr); //ICE: Segmentation fault +// using fun_ptr_t = decltype(F3::fun_ptr); //ICE: Segmentation fault + F3(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template struct F4 { + static R fun_not_implemented(AA...); +// using fun_ptr_t = decltype(&fun_not_implemented); //OK + using fun_ptr_t = decltype(&F4::fun_not_implemented); //OK with aggregate initialization (no ctor) +// using fun_ptr_t = decltype(&F4::fun_not_implemented); //OK with aggregate initialization (no ctor) + fun_ptr_t fun_ptr; +}; +template struct F5 { //OK + static R fun_not_implemented(AA...); + using fun_ptr_t = decltype(&fun_not_implemented); + fun_ptr_t fun_ptr; + F5(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template struct F6 { + static R fun_not_implemented(AA...); +// using fun_ptr_t = decltype(&fun_not_implemented); //OK as in F5 + using fun_ptr_t = decltype(&F6::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238 +// using fun_ptr_t = decltype(&F6::fun_not_implemented); //ICE: in build_qualified_name, at cp/tree.c:2238 + fun_ptr_t fun_ptr; + F6(fun_ptr_t fun_ptr) : fun_ptr(fun_ptr) {} +}; +template F0(R(*fun_ptr)(AA...)) -> F0; +template F1(R(*fun_ptr)(AA...)) -> F1; +template F2(R(*fun_ptr)(AA...)) -> F2; +template F3(R(*fun_ptr)(AA...)) -> F3; +template F4(R(*fun_ptr)(AA...)) -> F4; +template F5(R(*fun_ptr)(AA...)) -> F5; +template F6(R(*fun_ptr)(AA...)) -> F6; + +int fun(int a) { + return a + 1; +} +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +void test() { + auto f0 = F0{&fun}; //OK + auto f1 = F1{&fun}; //OK + auto f2 = F2{&fun}; //OK + auto f3 = F3{&fun}; //ICE: Segmentation fault + auto f4 = F4{&fun}; //OK + auto f5 = F5{&fun}; //OK + auto f6 = F6{&fun}; //ICE: in build_qualified_name, at cp/tree.c:2238 +}