From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 EA8BB3858418 for ; Mon, 1 May 2023 19:59:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EA8BB3858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682971166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lvk9no9u50iR238Z9iqcYiZMFqOY60B1uJMoIDwwa+E=; b=UU1PMU5oWhRuf6ZcKxxkvImmDyqOwgxgdFHR0XDlNGxKFGWLMaCXcF4ZY+/l3VEKjnLua3 sCFU1S53pDv/O3pEATNVnRNAhRCvnhYW6w36ZynKfc5LmuyeggQHKLUj0edjR4douPjJdQ t62C5CuveispFNYO7UY7lCT9ydPv3iQ= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-cxsvhyZKNdiYzGXay1fYrw-1; Mon, 01 May 2023 15:59:11 -0400 X-MC-Unique: cxsvhyZKNdiYzGXay1fYrw-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3ef30a89abbso16243181cf.2 for ; Mon, 01 May 2023 12:59:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682971146; x=1685563146; 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=lvk9no9u50iR238Z9iqcYiZMFqOY60B1uJMoIDwwa+E=; b=OuQsWZ0CpME+3wAs8Lu13r/ibVbfTDivz5ZvkjHTzcOL5/OP1jlj+5xuHY++UwQ4+e GkAHSm9ShmgknHdLYwWDsS5Wc0bxBUloYW1ZAJlRfkCfVRUBJZzk9RvmpnAbYnSX+2pM dwXi99pxRWu6rSIiIRvL9pbT6aElcoT3jC02NO8NVbwhA6ABBqnHGF23KlJLTdazjfKD gJhzaurGV/XHbMmgBgF+MMfLZPrbx0LUuyyy71MVkGH4LJ4N95xH775L7tHYUKPUEWAE 5ScesI+XEYgz16HNg+a2kIuhuqMopW7vjN4BDOhfO6iVxKlI1aDAL8I7wxsoa/SQ2HNQ ntcA== X-Gm-Message-State: AC+VfDzEoDRn4TkeJNIDnaUw5QW3JIV+hxSOO3Fp3tLNxPeFEcjI7bCs Ruux50t9VD+frLOayOQK0nfbtrONwoENf0CIPfgryCr7lFAMcGje4wy+UjNQqI/ClXIdbWuCFFQ 6bjo/cS2FYNH0tyIi/y8md+NdziTr61TFkRhwRghdaLk2zW7pdffLsnk4gwCyFUm+/nsrrL/1pb 8= X-Received: by 2002:ac8:574d:0:b0:3e6:35ec:8a9f with SMTP id 13-20020ac8574d000000b003e635ec8a9fmr25218843qtx.59.1682971145864; Mon, 01 May 2023 12:59:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4l9E/+S5cM/SM9c8Bj4Etf4w/YtX/LnLrpdq5tIkOgZE/AxsRzvrrmvrqOl+1HMbeT4fJY4g== X-Received: by 2002:ac8:574d:0:b0:3e6:35ec:8a9f with SMTP id 13-20020ac8574d000000b003e635ec8a9fmr25218817qtx.59.1682971145438; Mon, 01 May 2023 12:59:05 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 9-20020ac85909000000b003ef573e24cfsm9303705qty.12.2023.05.01.12.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:59:05 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 1/2] c++: potentiality of templated memfn call [PR109480] Date: Mon, 1 May 2023 15:59:01 -0400 Message-ID: <20230501195902.1915703-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.1.459.g48d89b51b3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.8 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,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 List-Id: Here we're incorrectly deeming the templated call a.g() inside b's initializer as potentially constant, despite g being non-constexpr, which leads to us wastefully instantiating the initializer ahead of time and triggering a bug in access checking deferral (which will get fixed in the subsequent patch). This patch fixes this by calling get_fns earlier during potentiality checking so that we also handle the templated form of a member function call (whose overall callee is a COMPONENT_REF) when checking if the called function is constexpr etc. PR c++/109480 gcc/cp/ChangeLog: * constexpr.cc (potential_constant_expression_1) : Reorganize to call get_fns sooner. Remove dead store to 'fun'. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/noexcept59.C: Make e() constexpr so that the expected "without object" diagnostic isn't replaced by a "call to non-constexpr function" diagnostic. * g++.dg/template/non-dependent25.C: New test. --- gcc/cp/constexpr.cc | 16 ++++++++-------- gcc/testsuite/g++.dg/cpp0x/noexcept59.C | 2 +- gcc/testsuite/g++.dg/template/non-dependent25.C | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent25.C diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index d1097764b10..29d872d0a5e 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -9132,6 +9132,10 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, if (fun && is_overloaded_fn (fun)) { + if (!RECUR (fun, true)) + return false; + fun = get_fns (fun); + if (TREE_CODE (fun) == FUNCTION_DECL) { if (builtin_valid_in_constant_expr_p (fun)) @@ -9167,7 +9171,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, expression the address will be folded away, so look through it now. */ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fun) - && !DECL_CONSTRUCTOR_P (fun)) + && !DECL_CONSTRUCTOR_P (fun) + && !processing_template_decl) { tree x = get_nth_callarg (t, 0); if (is_this_parameter (x)) @@ -9182,16 +9187,11 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, bool now, i = 1; } } - else - { - if (!RECUR (fun, true)) - return false; - fun = get_first_fn (fun); - } + + fun = OVL_FIRST (fun); /* Skip initial arguments to base constructors. */ if (DECL_BASE_CONSTRUCTOR_P (fun)) i = num_artificial_parms_for (fun); - fun = DECL_ORIGIN (fun); } else if (fun) { diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept59.C b/gcc/testsuite/g++.dg/cpp0x/noexcept59.C index c752601ba09..1dc826d3111 100644 --- a/gcc/testsuite/g++.dg/cpp0x/noexcept59.C +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept59.C @@ -3,7 +3,7 @@ template class A { - void e (); + constexpr bool e () { return true; }; bool f (int() noexcept(this->e())); // { dg-error "this" } bool g (int() noexcept(e())); // { dg-error "without object" } }; diff --git a/gcc/testsuite/g++.dg/template/non-dependent25.C b/gcc/testsuite/g++.dg/template/non-dependent25.C new file mode 100644 index 00000000000..a2f9801e11f --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent25.C @@ -0,0 +1,14 @@ +// PR c++/109480 + +template +struct A { + void f() { + A a; + const bool b = a.g(); + } + +private: + bool g() const; +}; + +template struct A; -- 2.40.1.459.g48d89b51b3