From patchwork Thu Mar 16 22:12:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 70985 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp22252wrt; Thu, 16 Mar 2023 15:13:18 -0700 (PDT) X-Google-Smtp-Source: AK7set/jCQ5Q5wq9dlDt8t4cdtPaoGCYI9XG6glJZMMbvKw6qbJxTgA2LBl+vCxL/AQxOyaFvuY+ X-Received: by 2002:a17:906:7f0f:b0:884:fd73:8053 with SMTP id d15-20020a1709067f0f00b00884fd738053mr12285710ejr.9.1679004798806; Thu, 16 Mar 2023 15:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679004798; cv=none; d=google.com; s=arc-20160816; b=gxhSu+MsemYnMW74Wm4k3JNLdBCcBNU248y2J/m1rO7OMa08WgtDqk14HK3q01QgLa 14XI+BTuxX4aWxtqx2Jyt1OYtaB2EWRJvKaU3+V1LT7va56nsspBqZK2JX1xb1bXtkFC FVRWc5FUkL+q+YNbGxBRl8RFq+fKRdRh74uOV0pWmtxkNf4xxPC47oqsrgyVtDcZDrx0 Fn6YXuh/Vir774FqVvJYJBnIUPesbgJ7t1JBYUFAwrlN1UvKwCnrr7gEkf7egNwh61vt mfWn/TLGCx47om2Lt/z8keYpkov+PiQmtP2YNrHyJadirRftx/zg9pjmNh3VY1Q/kNwo RErg== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=HHFKaCHziDLn3IT5G3viPawaIgwokIv/qNWeG9apei0=; b=r7b69mn3fDEhEpX3TH58liucxdgW8+AN9bY2s78RDzUtxaJqwK4p+5JJkxcqHt49Im ihgX4wUon11Pf/J35IMCGVfBXbMnaGk33jpR15zwF3zS20kRTO+z63xW/EAJ4sgTzvwl 7FCiRy8Q/JJVnYBI60ZzEeyCEeHNs4qEXsYn8vi5mM/O/GCdsnVt6izVcF4juj23m5cq YS65QyPuRoRIsT3y2hihLcGzQwzvm1AyZEJHOO6dQi/ml0IyYLL21JA2wwVY1ij8pQOI 1jLmarcTTGsy/IjpiDc9Rm3WBT6ISZIkdIKZMSuFQek+xJqRmF+FJLrlMrEEycS06IID iPPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=IxAr89DU; 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 q7-20020a17090676c700b0092fb11f889bsi464885ejn.265.2023.03.16.15.13.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 15:13:18 -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=IxAr89DU; 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 5DE35385B53D for ; Thu, 16 Mar 2023 22:13:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DE35385B53D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679004793; bh=HHFKaCHziDLn3IT5G3viPawaIgwokIv/qNWeG9apei0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IxAr89DU6kL1qrxEv6kmDlv66Q//DVQI6hSkCGuKg5x7r3MAWKm2BX3PRAa2hVvWP 8BKBVnEX/c6MzlK1ehd8x0/1KRZ+JgQ3+x62rVW5MF7J0q43H+V9RpPO1Jh2oG0KiM kY2+6y3kFEHpDdmaOZtnOAvebf229TRuZ9BPNGyg= 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 8C6DC3858D35 for ; Thu, 16 Mar 2023 22:12:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C6DC3858D35 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-66jdBpWMP3qc16euoi2i8A-1; Thu, 16 Mar 2023 18:12:27 -0400 X-MC-Unique: 66jdBpWMP3qc16euoi2i8A-1 Received: by mail-qv1-f70.google.com with SMTP id j13-20020a0cc34d000000b005a37f812e48so1829068qvi.12 for ; Thu, 16 Mar 2023 15:12:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679004746; 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=HHFKaCHziDLn3IT5G3viPawaIgwokIv/qNWeG9apei0=; b=uEkASAP2qovBbT38b/hFMPZcIbveeGJVVF/R2FuTzFI6YJSjtEPIibXVcZPWHlXkQc 0R+l28qnXKwpJKdwXaNNPpAokAN+DGl3iG6Rb1MZ3j3q44TqGVHt70A1fM7licqB8ECS INPooOiRQV1XskmJmBCb+dSkmOjE1coOqozzfqEo1R5Nlw2P2Q9IxtrmdYUMgPCaKBpV VXgYu4FMd2J7Aie952uuVyM6XW8lznVlRAoU0qMB4tNHZJmtQeadsNt6hVy2ePErutI3 HNtZUAXz8ZnbwdPyKO8TgKa6G1h/ZcW3wCtmnVft5sKLA/vQzUWTp1CWROrZ831i5roM t8hw== X-Gm-Message-State: AO0yUKUTlAaNoSaPTp3fVO6rL37RO93wH8MTCrS/36cEwbcfX0dS6JsA EG5JRMk6uiRfmpENsFRIt3z/L1SW09Uf8OkqMHSQnVIbztiEuet0fUEhUCg8F7HT0C6ZnClzQhe EgV2VTfUPGmV6HC5nhl9Ahl9OzFfpFb5jfWg8jqw9o5Y1rv7BuWUDmgm/mNPLtTUSLMiOsJtWOA == X-Received: by 2002:a05:622a:47:b0:3d7:66ea:b948 with SMTP id y7-20020a05622a004700b003d766eab948mr8190667qtw.54.1679004746253; Thu, 16 Mar 2023 15:12:26 -0700 (PDT) X-Received: by 2002:a05:622a:47:b0:3d7:66ea:b948 with SMTP id y7-20020a05622a004700b003d766eab948mr8190622qtw.54.1679004745804; Thu, 16 Mar 2023 15:12:25 -0700 (PDT) Received: from jason.cygnus.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 i16-20020ac871d0000000b003d9a69b4876sm429872qtp.11.2023.03.16.15.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 15:12:25 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: __func__ and local class DMI [PR105809] Date: Thu, 16 Mar 2023 18:12:23 -0400 Message-Id: <20230316221223.1138825-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill 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?1760564135958636231?= X-GMAIL-MSGID: =?utf-8?q?1760564135958636231?= Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- As in 108242, we need to instantiate in the context of the enclosing function, not after it's gone. PR c++/105809 gcc/cp/ChangeLog: * init.cc (get_nsdmi): Split out... (maybe_instantiate_nsdmi_init): ...this function. * cp-tree.h: Declare it. * pt.cc (tsubst_expr): Use it. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/constexpr-__func__3.C: New test. --- gcc/cp/cp-tree.h | 1 + gcc/cp/init.cc | 27 ++++++++++++------- gcc/cp/pt.cc | 6 +++++ .../g++.dg/cpp0x/constexpr-__func__3.C | 15 +++++++++++ 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C base-commit: b323f52ccf966800297b0520b9e1d4b3951db525 diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index dfc1c845768..b74c18b03ad 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -7086,6 +7086,7 @@ extern bool is_copy_initialization (tree); extern tree build_zero_init (tree, tree, bool); extern tree build_value_init (tree, tsubst_flags_t); extern tree build_value_init_noctor (tree, tsubst_flags_t); +extern tree maybe_instantiate_nsdmi_init (tree, tsubst_flags_t); extern tree get_nsdmi (tree, bool, tsubst_flags_t); extern tree build_offset_ref (tree, tree, bool, tsubst_flags_t); diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 1b7d3d8fe3e..90302372340 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -561,18 +561,16 @@ perform_target_ctor (tree init) return init; } -/* Return the non-static data initializer for FIELD_DECL MEMBER. */ +/* Instantiate the default member initializer of MEMBER, if needed. + Only get_nsdmi should use the return value of this function. */ static GTY((cache)) decl_tree_cache_map *nsdmi_inst; tree -get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) +maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain) { - tree init; - tree save_ccp = current_class_ptr; - tree save_ccr = current_class_ref; - - if (DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) + tree init = DECL_INITIAL (member); + if (init && DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member)) { init = DECL_INITIAL (DECL_TI_TEMPLATE (member)); location_t expr_loc @@ -642,8 +640,19 @@ get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) input_location = sloc; } } - else - init = DECL_INITIAL (member); + + return init; +} + +/* Return the non-static data initializer for FIELD_DECL MEMBER. */ + +tree +get_nsdmi (tree member, bool in_ctor, tsubst_flags_t complain) +{ + tree save_ccp = current_class_ptr; + tree save_ccr = current_class_ref; + + tree init = maybe_instantiate_nsdmi_init (member, complain); if (init && TREE_CODE (init) == DEFERRED_PARSE) { diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1072882e1a8..056b8c7abad 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -19353,6 +19353,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) /* Closures are handled by the LAMBDA_EXPR. */ gcc_assert (!LAMBDA_TYPE_P (TREE_TYPE (t))); complete_type (tmp); + tree save_ccp = current_class_ptr; + tree save_ccr = current_class_ref; for (tree fld = TYPE_FIELDS (tmp); fld; fld = DECL_CHAIN (fld)) if ((VAR_P (fld) || (TREE_CODE (fld) == FUNCTION_DECL @@ -19360,6 +19362,10 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl) && DECL_TEMPLATE_INSTANTIATION (fld)) instantiate_decl (fld, /*defer_ok=*/false, /*expl_inst_class=*/false); + else if (TREE_CODE (fld) == FIELD_DECL) + maybe_instantiate_nsdmi_init (fld, tf_warning_or_error); + current_class_ptr = save_ccp; + current_class_ref = save_ccr; } break; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C new file mode 100644 index 00000000000..365a4e00c5f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-__func__3.C @@ -0,0 +1,15 @@ +// PR c++/105809 +// { dg-do compile { target c++11 } } + +template void hh() { ss t; } + +template +int f(void) +{ + constexpr char const* cc = __func__; + struct j{ char const* kk=cc; }; + hh(); + return 0; +} + +int t = f<1>();