mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 19:03:59 +08:00
c++: Don't ICE to build private access error message [PR116323]
We currently ICE upon the following code while building the "[...] is private within this context" error message === cut here === class A { enum Enum{}; }; template<typename E, template<typename> class Alloc> class B : private Alloc<E>, private A {}; template<typename E, template<typename> class Alloc> int B<E, Alloc>::foo (Enum m) { return 42; } === cut here === The problem is that since r11-6880, after detecting that Enum cannot be accessed in B, enforce_access will access the TYPE_BINFO of all the bases of B, which ICEs for any that is a BOUND_TEMPLATE_TEMPLATE_PARM. This patch simply skips such bases. PR c++/116323 gcc/cp/ChangeLog: * search.cc (get_parent_with_private_access): Only call access_in_type for RECORD_OR_UNION_TYPE_P base BINFOs. gcc/testsuite/ChangeLog: * g++.dg/template/access43.C: New test.
This commit is contained in:
parent
f9e9ba9563
commit
19831baf49
@ -160,12 +160,16 @@ get_parent_with_private_access (tree decl, tree binfo)
|
|||||||
|
|
||||||
tree base_binfo = NULL_TREE;
|
tree base_binfo = NULL_TREE;
|
||||||
|
|
||||||
/* Iterate through immediate parent classes. */
|
/* Iterate through immediate parent classes.
|
||||||
|
Note that the base list might contain WILDCARD_TYPE_P types, that
|
||||||
|
should be ignored here. */
|
||||||
for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
|
for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
|
||||||
{
|
{
|
||||||
|
tree base_binfo_type = BINFO_TYPE (base_binfo);
|
||||||
/* This parent had private access. Therefore that's why BINFO can't
|
/* This parent had private access. Therefore that's why BINFO can't
|
||||||
access DECL. */
|
access DECL. */
|
||||||
if (access_in_type (BINFO_TYPE (base_binfo), decl) == ak_private)
|
if (RECORD_OR_UNION_TYPE_P (base_binfo_type)
|
||||||
|
&& access_in_type (base_binfo_type, decl) == ak_private)
|
||||||
return base_binfo;
|
return base_binfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
gcc/testsuite/g++.dg/template/access43.C
Normal file
11
gcc/testsuite/g++.dg/template/access43.C
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// PR c++/116323
|
||||||
|
// { dg-do "compile" }
|
||||||
|
// { dg-additional-options "-Wno-template-body" }
|
||||||
|
|
||||||
|
class A { enum Enum{}; };
|
||||||
|
|
||||||
|
template<typename E, template<typename> class Alloc>
|
||||||
|
class B : private Alloc<E>, private A {};
|
||||||
|
|
||||||
|
template<typename E, template<typename> class Alloc>
|
||||||
|
int B<E, Alloc>::foo (Enum m) { return 42; } // { dg-error "is private" }
|
Loading…
Reference in New Issue
Block a user