public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Patrick Palka <ppalka@redhat.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 2/2] c++: non-dep init folding and access checking [PR109480]
Date: Tue, 2 May 2023 14:35:40 -0400	[thread overview]
Message-ID: <d846be53-d5d6-ab5d-15cb-b124d54c1b62@redhat.com> (raw)
In-Reply-To: <20230501195902.1915703-2-ppalka@redhat.com>

On 5/1/23 15:59, Patrick Palka wrote:
> enforce_access currently inspects processing_template_decl to determine
> whether to defer the given access check until instantiation time.  But
> using this flag is unreliable because it gets cleared during e.g.
> non-dependent initializer folding, and can lead to premature access
> check failures as in the below testcase.  It seems better to inspect
> current_template_parms instead.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK
> for trunk?

OK.

> 	PR c++/109480
> 
> gcc/cp/ChangeLog:
> 
> 	* semantics.cc (enforce_access): Check current_template_parms
> 	instead of processing_template_decl when determining whether
> 	to defer the access check.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/non-dependent25a.C: New test.
> ---
>   gcc/cp/semantics.cc                             |  2 +-
>   .../g++.dg/template/non-dependent25a.C          | 17 +++++++++++++++++
>   2 files changed, 18 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/non-dependent25a.C
> 
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 9ba316ab3be..474da71bff6 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -346,7 +346,7 @@ enforce_access (tree basetype_path, tree decl, tree diag_decl,
>       }
>   
>     tree cs = current_scope ();
> -  if (processing_template_decl
> +  if (current_template_parms
>         && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL))
>       if (tree template_info = get_template_info (cs))
>         {
> diff --git a/gcc/testsuite/g++.dg/template/non-dependent25a.C b/gcc/testsuite/g++.dg/template/non-dependent25a.C
> new file mode 100644
> index 00000000000..902e537ec09
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/non-dependent25a.C
> @@ -0,0 +1,17 @@
> +// PR c++/109480
> +// A version of non-dependent25.C where b's initializer is a constant
> +// expression.
> +// { dg-do compile { target c++11 } }
> +
> +template<class T>
> +struct A {
> +  void f() {
> +    constexpr A<int> a;
> +    const bool b = a.g(); // { dg-bogus "private" }
> +  }
> +
> +private:
> +  constexpr bool g() const { return true; }
> +};
> +
> +template struct A<int>;


  reply	other threads:[~2023-05-02 18:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-01 19:59 [PATCH 1/2] c++: potentiality of templated memfn call [PR109480] Patrick Palka
2023-05-01 19:59 ` [PATCH 2/2] c++: non-dep init folding and access checking [PR109480] Patrick Palka
2023-05-02 18:35   ` Jason Merrill [this message]
2023-05-02 18:34 ` [PATCH 1/2] c++: potentiality of templated memfn call [PR109480] Jason Merrill
2023-05-02 19:35   ` Patrick Palka
2023-05-02 19:53     ` Patrick Palka
2023-05-03 19:55       ` Jason Merrill
2023-05-03 20:50         ` Patrick Palka
2023-05-04 13:56           ` Jason Merrill
2023-05-12 16:12           ` Martin Jambor
2023-05-12 17:02             ` Patrick Palka
2023-05-12 17:13               ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d846be53-d5d6-ab5d-15cb-b124d54c1b62@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).