public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error
@ 2021-06-04 20:22 ppalka at gcc dot gnu.org
2021-06-04 20:27 ` [Bug c++/100918] " ppalka at gcc dot gnu.org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-04 20:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Bug ID: 100918
Summary: Naming a destructor as a qualified template-id results
in bogus access error
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ppalka at gcc dot gnu.org
Target Milestone: ---
The following testcase:
struct Outer {
template<class T>
struct Inner { ~Inner(); };
};
template<>
Outer::Inner<int>::~Inner<int>() {}
is rejected with
<stdin>: In destructor ‘Outer::Inner<T>::~Inner() [with T = int]’:
<stdin>:7:21: error: ‘template<class T> struct Outer::Inner’ is inaccessible
within this context
<stdin>:3:12: note: declared here
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
@ 2021-06-04 20:27 ` ppalka at gcc dot gnu.org
2021-06-04 20:33 ` ppalka at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-04 20:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
We began rejecting this starting with r9-4879.
If we replace the explicit specialization of Inner<int>::~Inner with a generic
definition
struct Outer {
public:
template <typename T>
struct Inner { ~Inner(); };
};
template <class T>
Outer::Inner<T>::~Inner<T>() {}
Outer::Inner<int> x;
then we started to reject this version after r11-1350.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
2021-06-04 20:27 ` [Bug c++/100918] " ppalka at gcc dot gnu.org
@ 2021-06-04 20:33 ` ppalka at gcc dot gnu.org
2021-06-04 21:12 ` [Bug c++/100918] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-04 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |ppalka at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2021-06-04
Status|UNCONFIRMED |ASSIGNED
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [9/10/11/12 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
2021-06-04 20:27 ` [Bug c++/100918] " ppalka at gcc dot gnu.org
2021-06-04 20:33 ` ppalka at gcc dot gnu.org
@ 2021-06-04 21:12 ` ppalka at gcc dot gnu.org
2021-06-07 16:06 ` cvs-commit at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-06-04 21:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |8.5.0
Known to fail| |10.3.0, 11.1.0, 9.4.0
Target Milestone|--- |9.5
Summary|Naming a destructor as a |[9/10/11/12 Regression]
|qualified template-id |Naming a destructor as a
|results in bogus access |qualified template-id
|error |results in bogus access
| |error
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [9/10/11/12 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (2 preceding siblings ...)
2021-06-04 21:12 ` [Bug c++/100918] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
@ 2021-06-07 16:06 ` cvs-commit at gcc dot gnu.org
2021-07-13 14:03 ` cvs-commit at gcc dot gnu.org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-06-07 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:6cb35b606c39d5f21f3298c77bfbcaaef3fbc872
commit r12-1263-g6cb35b606c39d5f21f3298c77bfbcaaef3fbc872
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Jun 7 12:02:08 2021 -0400
c++: access of dtor named by qualified template-id [PR100918]
Here, when resolving the destructor named by Inner<int>::~Inner<int>
(which is valid until C++20) we end up in cp_parser_lookup_name called
indirectly from cp_parser_template_id to look up the name Inner from
the scope Inner<int>. The lookup naturally finds the injected-class-name,
and because the flag is_template is true, we adjust this lookup result
to the TEMPLATE_DECL Inner. We then check access of this adjusted
lookup result. But this access check fails because the lookup scope is
Inner<int> and the context_for_name_lookup for the TEMPLATE_DECL is
Outer (whereas for the injected-class-name it's also Inner<int>).
The simplest fix seems to be to check access of the original lookup
result (the injected-class-name) instead of the adjusted result (the
TEMPLATE_DECL). So this patch moves the access check in
cp_parser_lookup_name to before the injected-class-name adjustment.
PR c++/100918
gcc/cp/ChangeLog:
* parser.c (cp_parser_lookup_name): Check access of the lookup
result before we potentially adjust an injected-class-name to
its TEMPLATE_DECL.
gcc/testsuite/ChangeLog:
* g++.dg/template/access38.C: New test.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [9/10/11/12 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (3 preceding siblings ...)
2021-06-07 16:06 ` cvs-commit at gcc dot gnu.org
@ 2021-07-13 14:03 ` cvs-commit at gcc dot gnu.org
2021-07-13 14:04 ` [Bug c++/100918] [9/10 " ppalka at gcc dot gnu.org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-07-13 14:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Patrick Palka
<ppalka@gcc.gnu.org>:
https://gcc.gnu.org/g:6530cf0d50ae4c23c8e1ba908d1d0d4472e2966c
commit r11-8727-g6530cf0d50ae4c23c8e1ba908d1d0d4472e2966c
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Jun 7 12:02:08 2021 -0400
c++: access of dtor named by qualified template-id [PR100918]
Here, when resolving the destructor named by Inner<int>::~Inner<int>
(which is valid until C++20) we end up in cp_parser_lookup_name called
indirectly from cp_parser_template_id to look up the name Inner from
the scope Inner<int>. The lookup naturally finds the injected-class-name,
and because the flag is_template is true, we adjust this lookup result
to the TEMPLATE_DECL Inner. We then check access of this adjusted
lookup result. But this access check fails because the lookup scope is
Inner<int> and the context_for_name_lookup for the TEMPLATE_DECL is
Outer (whereas for the injected-class-name it's also Inner<int>).
The simplest fix seems to be to check access of the original lookup
result (the injected-class-name) instead of the adjusted result (the
TEMPLATE_DECL). So this patch moves the access check in
cp_parser_lookup_name to before the injected-class-name adjustment.
PR c++/100918
gcc/cp/ChangeLog:
* parser.c (cp_parser_lookup_name): Check access of the lookup
result before we potentially adjust an injected-class-name to
its TEMPLATE_DECL.
gcc/testsuite/ChangeLog:
* g++.dg/template/access38.C: New test.
(cherry picked from commit 6cb35b606c39d5f21f3298c77bfbcaaef3fbc872)
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [9/10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (4 preceding siblings ...)
2021-07-13 14:03 ` cvs-commit at gcc dot gnu.org
@ 2021-07-13 14:04 ` ppalka at gcc dot gnu.org
2022-05-27 9:45 ` [Bug c++/100918] [10 " rguenth at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ppalka at gcc dot gnu.org @ 2021-07-13 14:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[9/10/11/12 Regression] |[9/10 Regression] Naming a
|Naming a destructor as a |destructor as a qualified
|qualified template-id |template-id results in
|results in bogus access |bogus access error
|error |
--- Comment #4 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for 11.2/12 so far
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (5 preceding siblings ...)
2021-07-13 14:04 ` [Bug c++/100918] [9/10 " ppalka at gcc dot gnu.org
@ 2022-05-27 9:45 ` rguenth at gcc dot gnu.org
2022-06-28 10:45 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27 9:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|9.5 |10.4
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (6 preceding siblings ...)
2022-05-27 9:45 ` [Bug c++/100918] [10 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:45 ` jakub at gcc dot gnu.org
2023-05-04 21:43 ` christian.prochaska@genode-labs.com
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|10.4 |10.5
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (7 preceding siblings ...)
2022-06-28 10:45 ` jakub at gcc dot gnu.org
@ 2023-05-04 21:43 ` christian.prochaska@genode-labs.com
2023-05-04 21:46 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: christian.prochaska@genode-labs.com @ 2023-05-04 21:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Christian Prochaska <christian.prochaska@genode-labs.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |christian.prochaska@genode-
| |labs.com
--- Comment #7 from Christian Prochaska <christian.prochaska@genode-labs.com> ---
Since the commit above the following test fails. Is this correct?
class T1 { };
class T2 { };
template <typename T>
class A { };
class B : A<T1> { };
class C : B
{
class D : A<T2> { };
};
test.cc:11:19: error: ‘class A<T1> A<T1>::A’ is private within this context
11 | class D : A<T2> { };
| ^~~~~
test.cc:7:7: note: declared private here
7 | class B : A<T1> { };
| ^
When class B is left out, the error does not occur:
class T1 { };
class T2 { };
template <typename T>
class A { };
class C : A<T1>
{
class D : A<T2> { };
};
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (8 preceding siblings ...)
2023-05-04 21:43 ` christian.prochaska@genode-labs.com
@ 2023-05-04 21:46 ` pinskia at gcc dot gnu.org
2023-05-04 21:49 ` pinskia at gcc dot gnu.org
2023-07-07 9:41 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-04 21:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Christian Prochaska from comment #7)
> Since the commit above the following test fails. Is this correct?
>
> class T1 { };
> class T2 { };
>
> template <typename T>
> class A { };
>
> class B : A<T1> { };
>
> class C : B
> {
> class D : A<T2> { };
> };
>
> test.cc:11:19: error: ‘class A<T1> A<T1>::A’ is private within this context
> 11 | class D : A<T2> { };
> | ^~~~~
> test.cc:7:7: note: declared private here
> 7 | class B : A<T1> { };
> | ^
Yes it should be rejected as A is a private name of A<T1> and A<T1> is private
to B. clang rejects it for the same reason though has a better error message:
<source>:12:19: error: 'A' is a private member of 'A<T1>'
class D : A<T2> { };
^
<source>:8:11: note: constrained by implicitly private inheritance here
class B : A<T1> { };
^~~~~
<source>:6:7: note: member is declared here
class A { };
^
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (9 preceding siblings ...)
2023-05-04 21:46 ` pinskia at gcc dot gnu.org
@ 2023-05-04 21:49 ` pinskia at gcc dot gnu.org
2023-07-07 9:41 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-04 21:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #8)
> (In reply to Christian Prochaska from comment #7)
> > Since the commit above the following test fails. Is this correct?
>
> >
> > class T1 { };
> > class T2 { };
> >
> > template <typename T>
> > class A { };
> >
> > class B : A<T1> { };
> >
> > class C : B
> > {
> > class D : A<T2> { };
> > };
> >
> > test.cc:11:19: error: ‘class A<T1> A<T1>::A’ is private within this context
> > 11 | class D : A<T2> { };
> > | ^~~~~
> > test.cc:7:7: note: declared private here
> > 7 | class B : A<T1> { };
> > | ^
>
>
>
> Yes it should be rejected as A is a private name of A<T1> and A<T1> is
> private to B. clang rejects it for the same reason though has a better error
> message:
> <source>:12:19: error: 'A' is a private member of 'A<T1>'
> class D : A<T2> { };
> ^
> <source>:8:11: note: constrained by implicitly private inheritance here
> class B : A<T1> { };
> ^~~~~
> <source>:6:7: note: member is declared here
> class A { };
> ^
An obvious fix is to use ::A<T2> while inside C .
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug c++/100918] [10 Regression] Naming a destructor as a qualified template-id results in bogus access error
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
` (10 preceding siblings ...)
2023-05-04 21:49 ` pinskia at gcc dot gnu.org
@ 2023-07-07 9:41 ` rguenth at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 9:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100918
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.5.0
Resolution|--- |FIXED
Known to work| |11.2.0, 12.0
Target Milestone|10.5 |11.2
Status|ASSIGNED |RESOLVED
--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed in GCC 11.2+
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-07-07 9:41 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-04 20:22 [Bug c++/100918] New: Naming a destructor as a qualified template-id results in bogus access error ppalka at gcc dot gnu.org
2021-06-04 20:27 ` [Bug c++/100918] " ppalka at gcc dot gnu.org
2021-06-04 20:33 ` ppalka at gcc dot gnu.org
2021-06-04 21:12 ` [Bug c++/100918] [9/10/11/12 Regression] " ppalka at gcc dot gnu.org
2021-06-07 16:06 ` cvs-commit at gcc dot gnu.org
2021-07-13 14:03 ` cvs-commit at gcc dot gnu.org
2021-07-13 14:04 ` [Bug c++/100918] [9/10 " ppalka at gcc dot gnu.org
2022-05-27 9:45 ` [Bug c++/100918] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:45 ` jakub at gcc dot gnu.org
2023-05-04 21:43 ` christian.prochaska@genode-labs.com
2023-05-04 21:46 ` pinskia at gcc dot gnu.org
2023-05-04 21:49 ` pinskia at gcc dot gnu.org
2023-07-07 9:41 ` rguenth at gcc dot gnu.org
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).