public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/1] c++: access of class-scope partial tmpl spec
@ 2024-01-03 20:06 Patrick Palka
  2024-01-15 19:38 ` Patrick Palka
  2024-01-15 19:49 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Patrick Palka @ 2024-01-03 20:06 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
OK for trunk?

-- >8 --

Since partial template specializations can't be named directly, access
control (when declared at class scope) doesn't apply to them, so we
shouldn't have to set their TREE_PRIVATE / TREE_PROTECTED.  This code was
added by r10-4833-gcce3c9db9e6ffa for PR92078, but it seems better to
just disable the relevant access consistency check for partial template
specializations so that we also accept the below testcase.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_check_access_in_redeclaration): Don't
	check access for a partial specialization.
	* pt.cc (maybe_new_partial_specialization): Don't set TREE_PRIVATE
	or TREE_PROTECTED on the newly created partial specialization.

gcc/testsuite/ChangeLog:

	* g++.dg/template/partial-specialization14.C: New test.
---
 gcc/cp/parser.cc                                  |  3 ++-
 gcc/cp/pt.cc                                      |  2 --
 .../g++.dg/template/partial-specialization14.C    | 15 +++++++++++++++
 3 files changed, 17 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization14.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 37536faf2cf..85da15651b2 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -35062,7 +35062,8 @@ static void
 cp_parser_check_access_in_redeclaration (tree decl, location_t location)
 {
   if (!decl
-      || (!CLASS_TYPE_P (TREE_TYPE (decl))
+      || (!(CLASS_TYPE_P (TREE_TYPE (decl))
+	    && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl)))
 	  && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE))
     return;
 
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 154ac76cb65..afd1df4f3d7 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -978,8 +978,6 @@ maybe_new_partial_specialization (tree& type)
       tree d = create_implicit_typedef (DECL_NAME (tmpl), t);
       DECL_CONTEXT (d) = TYPE_CONTEXT (t);
       DECL_SOURCE_LOCATION (d) = input_location;
-      TREE_PRIVATE (d) = (current_access_specifier == access_private_node);
-      TREE_PROTECTED (d) = (current_access_specifier == access_protected_node);
       TREE_PUBLIC (d) = TREE_PUBLIC (DECL_TEMPLATE_RESULT (tmpl));
 
       set_instantiating_module (d);
diff --git a/gcc/testsuite/g++.dg/template/partial-specialization14.C b/gcc/testsuite/g++.dg/template/partial-specialization14.C
new file mode 100644
index 00000000000..ac7bc9ed7f1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/partial-specialization14.C
@@ -0,0 +1,15 @@
+// Verify we don't care about the access specifier when declaring
+// a partial template specialization of a member class template.
+
+struct A1 {
+  template<class T> struct B { };
+private:
+  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
+};
+
+struct A2 {
+  template<class T> struct B { };
+  template<class T> struct B<T*>;
+private:
+  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
+};
-- 
2.43.0.254.ga26002b628


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/1] c++: access of class-scope partial tmpl spec
  2024-01-03 20:06 [PATCH 2/1] c++: access of class-scope partial tmpl spec Patrick Palka
@ 2024-01-15 19:38 ` Patrick Palka
  2024-01-15 19:49 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2024-01-15 19:38 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason

On Wed, Jan 3, 2024 at 3:06 PM Patrick Palka <ppalka@redhat.com> wrote:
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?

Ping.

>
> -- >8 --
>
> Since partial template specializations can't be named directly, access
> control (when declared at class scope) doesn't apply to them, so we
> shouldn't have to set their TREE_PRIVATE / TREE_PROTECTED.  This code was
> added by r10-4833-gcce3c9db9e6ffa for PR92078, but it seems better to
> just disable the relevant access consistency check for partial template
> specializations so that we also accept the below testcase.
>
> gcc/cp/ChangeLog:
>
>         * parser.cc (cp_parser_check_access_in_redeclaration): Don't
>         check access for a partial specialization.
>         * pt.cc (maybe_new_partial_specialization): Don't set TREE_PRIVATE
>         or TREE_PROTECTED on the newly created partial specialization.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/template/partial-specialization14.C: New test.
> ---
>  gcc/cp/parser.cc                                  |  3 ++-
>  gcc/cp/pt.cc                                      |  2 --
>  .../g++.dg/template/partial-specialization14.C    | 15 +++++++++++++++
>  3 files changed, 17 insertions(+), 3 deletions(-)
>  create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization14.C
>
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 37536faf2cf..85da15651b2 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -35062,7 +35062,8 @@ static void
>  cp_parser_check_access_in_redeclaration (tree decl, location_t location)
>  {
>    if (!decl
> -      || (!CLASS_TYPE_P (TREE_TYPE (decl))
> +      || (!(CLASS_TYPE_P (TREE_TYPE (decl))
> +           && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl)))
>           && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE))
>      return;
>
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 154ac76cb65..afd1df4f3d7 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -978,8 +978,6 @@ maybe_new_partial_specialization (tree& type)
>        tree d = create_implicit_typedef (DECL_NAME (tmpl), t);
>        DECL_CONTEXT (d) = TYPE_CONTEXT (t);
>        DECL_SOURCE_LOCATION (d) = input_location;
> -      TREE_PRIVATE (d) = (current_access_specifier == access_private_node);
> -      TREE_PROTECTED (d) = (current_access_specifier == access_protected_node);
>        TREE_PUBLIC (d) = TREE_PUBLIC (DECL_TEMPLATE_RESULT (tmpl));
>
>        set_instantiating_module (d);
> diff --git a/gcc/testsuite/g++.dg/template/partial-specialization14.C b/gcc/testsuite/g++.dg/template/partial-specialization14.C
> new file mode 100644
> index 00000000000..ac7bc9ed7f1
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/partial-specialization14.C
> @@ -0,0 +1,15 @@
> +// Verify we don't care about the access specifier when declaring
> +// a partial template specialization of a member class template.
> +
> +struct A1 {
> +  template<class T> struct B { };
> +private:
> +  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
> +};
> +
> +struct A2 {
> +  template<class T> struct B { };
> +  template<class T> struct B<T*>;
> +private:
> +  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
> +};
> --
> 2.43.0.254.ga26002b628
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/1] c++: access of class-scope partial tmpl spec
  2024-01-03 20:06 [PATCH 2/1] c++: access of class-scope partial tmpl spec Patrick Palka
  2024-01-15 19:38 ` Patrick Palka
@ 2024-01-15 19:49 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2024-01-15 19:49 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 1/3/24 15:06, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look
> OK for trunk?

OK.

> -- >8 --
> 
> Since partial template specializations can't be named directly, access
> control (when declared at class scope) doesn't apply to them, so we
> shouldn't have to set their TREE_PRIVATE / TREE_PROTECTED.  This code was
> added by r10-4833-gcce3c9db9e6ffa for PR92078, but it seems better to
> just disable the relevant access consistency check for partial template
> specializations so that we also accept the below testcase.
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_check_access_in_redeclaration): Don't
> 	check access for a partial specialization.
> 	* pt.cc (maybe_new_partial_specialization): Don't set TREE_PRIVATE
> 	or TREE_PROTECTED on the newly created partial specialization.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/partial-specialization14.C: New test.
> ---
>   gcc/cp/parser.cc                                  |  3 ++-
>   gcc/cp/pt.cc                                      |  2 --
>   .../g++.dg/template/partial-specialization14.C    | 15 +++++++++++++++
>   3 files changed, 17 insertions(+), 3 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization14.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index 37536faf2cf..85da15651b2 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -35062,7 +35062,8 @@ static void
>   cp_parser_check_access_in_redeclaration (tree decl, location_t location)
>   {
>     if (!decl
> -      || (!CLASS_TYPE_P (TREE_TYPE (decl))
> +      || (!(CLASS_TYPE_P (TREE_TYPE (decl))
> +	    && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl)))
>   	  && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE))
>       return;
>   
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 154ac76cb65..afd1df4f3d7 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -978,8 +978,6 @@ maybe_new_partial_specialization (tree& type)
>         tree d = create_implicit_typedef (DECL_NAME (tmpl), t);
>         DECL_CONTEXT (d) = TYPE_CONTEXT (t);
>         DECL_SOURCE_LOCATION (d) = input_location;
> -      TREE_PRIVATE (d) = (current_access_specifier == access_private_node);
> -      TREE_PROTECTED (d) = (current_access_specifier == access_protected_node);
>         TREE_PUBLIC (d) = TREE_PUBLIC (DECL_TEMPLATE_RESULT (tmpl));
>   
>         set_instantiating_module (d);
> diff --git a/gcc/testsuite/g++.dg/template/partial-specialization14.C b/gcc/testsuite/g++.dg/template/partial-specialization14.C
> new file mode 100644
> index 00000000000..ac7bc9ed7f1
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/partial-specialization14.C
> @@ -0,0 +1,15 @@
> +// Verify we don't care about the access specifier when declaring
> +// a partial template specialization of a member class template.
> +
> +struct A1 {
> +  template<class T> struct B { };
> +private:
> +  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
> +};
> +
> +struct A2 {
> +  template<class T> struct B { };
> +  template<class T> struct B<T*>;
> +private:
> +  template<class T> struct B<T*> { }; // { dg-bogus "different access" }
> +};


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-15 19:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 20:06 [PATCH 2/1] c++: access of class-scope partial tmpl spec Patrick Palka
2024-01-15 19:38 ` Patrick Palka
2024-01-15 19:49 ` Jason Merrill

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).