8sa1-gcc/gcc/testsuite/g++.dg/cpp1z/using9.C
Anthony Sharp be246ac2d2 c++: Private parent access check for using decls [PR19377]
This bug was already mostly fixed by the patch for PR17314. This
patch continues that by ensuring that where a using decl is used,
causing an access failure to a child class because the using decl is
private, the compiler correctly points to the using decl as the
source of the problem.

gcc/cp/ChangeLog:

2021-03-10  Anthony Sharp  <anthonysharp15@gmail.com>

	* semantics.c (get_class_access_diagnostic_decl): New
	function that examines special cases when a parent
	class causes a private access failure.
	(enforce_access): Slightly modified to call function
	above.

gcc/testsuite/ChangeLog:

2021-03-10  Anthony Sharp  <anthonysharp15@gmail.com>

	* g++.dg/cpp1z/using9.C: New using decl test.

Co-authored-by: Jason Merrill <jason@redhat.com>
2021-03-17 19:11:02 -04:00

50 lines
1.0 KiB
C

/* { dg-do compile { target c++17 } } */
// Created for c++ PR19377
class A2
{
protected:
int separate(int a);
int separate(int a, int b);
int separate(int a, int b, int c);
int comma(int a);
int alone;
};
class A1
{
protected:
int separate();
int comma();
};
class A3
{
protected:
int comma(int a, int b);
};
class B:private A3, private A1, private A2
{
// Using decls in a comma-separated list.
using A2::comma, A3::comma, A1::comma; // { dg-message "declared" }
// Separate using statements.
using A2::separate; // { dg-message "declared" }
using A1::separate; // { dg-message "declared" }
// No ambiguity, just for the sake of it.
using A2::alone; // { dg-message "declared" }
};
class C:public B
{
void f()
{
comma(); // { dg-error "private" }
separate(); // { dg-error "private" }
separate(1); // { dg-error "private" }
separate(1, 2); // { dg-error "private" }
separate(1, 2, 3); // { dg-error "private" }
alone = 5; // { dg-error "private" }
}
};