2016-09-01 07:24:08 +08:00
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s
2011-02-28 08:40:07 +08:00
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify %s
2010-01-27 09:50:18 +08:00
// C++0x [class.access]p4:
// Access control is applied uniformly to all names, whether the
// names are referred to from declarations or expressions. In the
// case of overloaded function names, access control is applied to
// the function selected by overload resolution.
class Public { } PublicInst ;
class Protected { } ProtectedInst ;
class Private { } PrivateInst ;
namespace test0 {
class A {
public :
void foo ( Public & ) ;
protected :
void foo ( Protected & ) ; // expected-note 2 {{declared protected here}}
private :
void foo ( Private & ) ; // expected-note 2 {{declared private here}}
} ;
void test ( A * op ) {
op - > foo ( PublicInst ) ;
2010-02-10 17:31:12 +08:00
op - > foo ( ProtectedInst ) ; // expected-error {{'foo' is a protected member}}
op - > foo ( PrivateInst ) ; // expected-error {{'foo' is a private member}}
2010-01-27 09:50:18 +08:00
void ( A : : * a ) ( Public & ) = & A : : foo ;
2010-02-10 17:31:12 +08:00
void ( A : : * b ) ( Protected & ) = & A : : foo ; // expected-error {{'foo' is a protected member}}
void ( A : : * c ) ( Private & ) = & A : : foo ; // expected-error {{'foo' is a private member}}
2010-01-27 09:50:18 +08:00
}
}
2010-01-28 09:42:12 +08:00
// Member operators.
namespace test1 {
class A {
public :
void operator + ( Public & ) ;
void operator [ ] ( Public & ) ;
2010-01-28 09:54:34 +08:00
void operator ( ) ( Public & ) ;
2010-01-28 15:38:46 +08:00
typedef void ( * PublicSurrogate ) ( Public & ) ;
operator PublicSurrogate ( ) const ;
2010-01-28 09:42:12 +08:00
protected :
void operator + ( Protected & ) ; // expected-note {{declared protected here}}
void operator [ ] ( Protected & ) ; // expected-note {{declared protected here}}
2010-01-28 09:54:34 +08:00
void operator ( ) ( Protected & ) ; // expected-note {{declared protected here}}
2010-01-28 15:38:46 +08:00
typedef void ( * ProtectedSurrogate ) ( Protected & ) ;
operator ProtectedSurrogate ( ) const ; // expected-note {{declared protected here}}
2010-01-28 09:42:12 +08:00
private :
void operator + ( Private & ) ; // expected-note {{declared private here}}
void operator [ ] ( Private & ) ; // expected-note {{declared private here}}
2010-01-28 09:54:34 +08:00
void operator ( ) ( Private & ) ; // expected-note {{declared private here}}
2010-01-28 09:42:12 +08:00
void operator - ( ) ; // expected-note {{declared private here}}
2010-01-28 15:38:46 +08:00
typedef void ( * PrivateSurrogate ) ( Private & ) ;
operator PrivateSurrogate ( ) const ; // expected-note {{declared private here}}
2010-01-28 09:42:12 +08:00
} ;
void operator + ( const A & , Public & ) ;
void operator + ( const A & , Protected & ) ;
void operator + ( const A & , Private & ) ;
void operator - ( const A & ) ;
void test ( A & a , Public & pub , Protected & prot , Private & priv ) {
a + pub ;
2010-02-10 17:31:12 +08:00
a + prot ; // expected-error {{'operator+' is a protected member}}
a + priv ; // expected-error {{'operator+' is a private member}}
2010-01-28 09:42:12 +08:00
a [ pub ] ;
2010-02-10 17:31:12 +08:00
a [ prot ] ; // expected-error {{'operator[]' is a protected member}}
a [ priv ] ; // expected-error {{'operator[]' is a private member}}
2010-01-28 09:54:34 +08:00
a ( pub ) ;
2010-02-10 17:31:12 +08:00
a ( prot ) ; // expected-error {{'operator()' is a protected member}}
a ( priv ) ; // expected-error {{'operator()' is a private member}}
- a ; // expected-error {{'operator-' is a private member}}
2010-01-28 09:42:12 +08:00
const A & ca = a ;
ca + pub ;
ca + prot ;
ca + priv ;
- ca ;
2010-01-28 15:38:46 +08:00
// These are all surrogate calls
ca ( pub ) ;
2014-01-22 08:27:42 +08:00
ca ( prot ) ; // expected-error {{'operator void (*)(Protected &)' is a protected member}}
ca ( priv ) ; // expected-error {{'operator void (*)(Private &)' is a private member}}
2010-01-28 09:42:12 +08:00
}
}
2010-02-02 16:45:54 +08:00
// Implicit constructor calls.
namespace test2 {
class A {
private :
2016-09-01 07:24:08 +08:00
A ( ) ; // expected-note 1+{{declared private here}}
2010-02-02 16:45:54 +08:00
static A foo ;
} ;
2010-02-10 17:31:12 +08:00
A a ; // expected-error {{calling a private constructor}}
2010-02-02 16:45:54 +08:00
A A : : foo ; // okay
2010-04-22 02:47:17 +08:00
2016-09-01 07:24:08 +08:00
# if __cplusplus < 201103L
2011-05-26 07:16:36 +08:00
class B : A { } ; // expected-error {{base class 'test2::A' has private default constructor}}
2010-05-13 00:39:35 +08:00
B b ; // expected-note{{implicit default constructor}}
2010-04-22 02:47:17 +08:00
class C : virtual A {
public :
C ( ) ;
} ;
2010-04-22 03:52:01 +08:00
2011-05-26 07:16:36 +08:00
class D : C { } ; // expected-error {{inherited virtual base class 'test2::A' has private default constructor}}
2010-05-13 00:39:35 +08:00
D d ; // expected-note{{implicit default constructor}}
2016-09-01 07:24:08 +08:00
# else
class B : A { } ; // expected-note {{base class 'test2::A' has an inaccessible default constructor}}
B b ; // expected-error {{call to implicitly-deleted default constructor}}
// FIXME: Do a better job of explaining how we get here from class D.
class C : virtual A { // expected-note {{default constructor of 'D' is implicitly deleted because base class 'test2::A' has an inaccessible default constructor}}
public :
C ( ) ;
} ;
class D : C { } ;
D d ; // expected-error {{call to implicitly-deleted default constructor}}
# endif
2010-02-02 16:45:54 +08:00
}
// Implicit destructor calls.
namespace test3 {
2010-03-16 13:22:47 +08:00
class A {
2010-02-02 16:45:54 +08:00
private :
2010-03-26 14:57:13 +08:00
~ A ( ) ; // expected-note 2 {{declared private here}}
2010-02-02 16:45:54 +08:00
static A foo ;
} ;
2010-03-16 13:22:47 +08:00
A a ; // expected-error {{variable of type 'test3::A' has private destructor}}
2010-02-02 16:45:54 +08:00
A A : : foo ;
2010-03-26 14:57:13 +08:00
void foo ( A param ) { // okay
2010-03-16 13:22:47 +08:00
A local ; // expected-error {{variable of type 'test3::A' has private destructor}}
2010-02-02 16:45:54 +08:00
}
2010-03-16 13:22:47 +08:00
2016-09-01 07:24:08 +08:00
# if __cplusplus < 201103L
2010-03-17 05:39:52 +08:00
template < unsigned N > class Base { ~ Base ( ) ; } ; // expected-note 14 {{declared private here}}
class Base2 : virtual Base < 2 > { ~ Base2 ( ) ; } ; / / expected - note 3 { { declared private here } } \
// expected-error {{base class 'Base<2>' has private destructor}}
class Base3 : virtual Base < 3 > { public : ~ Base3 ( ) ; } ; // expected-error {{base class 'Base<3>' has private destructor}}
2010-03-16 13:22:47 +08:00
// These don't cause diagnostics because we don't need the destructor.
class Derived0 : Base < 0 > { ~ Derived0 ( ) ; } ;
class Derived1 : Base < 1 > { } ;
class Derived2 : / / expected - error { { inherited virtual base class ' Base < 2 > ' has private destructor } } \
// expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
Base < 0 > , // expected-error {{base class 'Base<0>' has private destructor}}
virtual Base < 1 > , // expected-error {{base class 'Base<1>' has private destructor}}
Base2 , // expected-error {{base class 'test3::Base2' has private destructor}}
virtual Base3
{
~ Derived2 ( ) { }
} ;
2010-03-16 13:36:30 +08:00
2010-03-17 05:39:52 +08:00
class Derived3 : / / expected - error 2 { { inherited virtual base class ' Base < 2 > ' has private destructor } } \
2010-05-13 00:39:35 +08:00
/ / expected - error 2 { { inherited virtual base class ' Base < 3 > ' has private destructor } } \
// expected-note 2{{implicit default constructor}}
2010-03-17 05:39:52 +08:00
Base < 0 > , // expected-error 2 {{base class 'Base<0>' has private destructor}}
virtual Base < 1 > , // expected-error 2 {{base class 'Base<1>' has private destructor}}
Base2 , // expected-error 2 {{base class 'test3::Base2' has private destructor}}
2010-03-16 13:36:30 +08:00
virtual Base3
2010-05-13 00:39:35 +08:00
{ } ;
2017-05-26 06:47:05 +08:00
Derived3 d3 ; / / expected - note 3 { { implicit default constructor } } \
2013-06-13 11:34:55 +08:00
// expected-note{{implicit destructor}}}
2016-09-01 07:24:08 +08:00
# else
template < unsigned N > class Base { ~ Base ( ) ; } ; // expected-note 4{{declared private here}}
class Base2 : virtual Base < 2 > { ~ Base2 ( ) ; } ; // expected-note 1{{declared private here}}
class Base3 : virtual Base < 3 > { public : ~ Base3 ( ) ; } ;
// These don't cause diagnostics because we don't need the destructor.
class Derived0 : Base < 0 > { ~ Derived0 ( ) ; } ;
class Derived1 : Base < 1 > { } ;
class Derived2 : / / expected - error { { inherited virtual base class ' Base < 2 > ' has private destructor } } \
// expected-error {{inherited virtual base class 'Base<3>' has private destructor}}
Base < 0 > , // expected-error {{base class 'Base<0>' has private destructor}}
virtual Base < 1 > , // expected-error {{base class 'Base<1>' has private destructor}}
Base2 , // expected-error {{base class 'test3::Base2' has private destructor}}
virtual Base3
{
~ Derived2 ( ) { }
} ;
class Derived3 :
Base < 0 > , // expected-note {{deleted because base class 'Base<0>' has an inaccessible destructor}}
virtual Base < 1 > ,
Base2 ,
virtual Base3
{ } ;
Derived3 d3 ; // expected-error {{implicitly-deleted default constructor}}
# endif
2010-02-02 16:45:54 +08:00
}
2010-03-15 17:07:48 +08:00
// Conversion functions.
namespace test4 {
class Base {
private :
operator Private ( ) ; // expected-note 4 {{declared private here}}
public :
2010-05-28 12:34:55 +08:00
operator Public ( ) ; // expected-note 2{{member is declared here}}
2010-03-15 17:07:48 +08:00
} ;
class Derived1 : private Base { / / expected - note 2 { { declared private here } } \
// expected-note {{constrained by private inheritance}}
Private test1 ( ) { return * this ; } // expected-error {{'operator Private' is a private member}}
Public test2 ( ) { return * this ; }
} ;
Private test1 ( Derived1 & d ) { return d ; } / / expected - error { { ' operator Private ' is a private member } } \
// expected-error {{cannot cast 'test4::Derived1' to its private base class}}
Public test2 ( Derived1 & d ) { return d ; } / / expected - error { { cannot cast ' test4 : : Derived1 ' to its private base class } } \
// expected-error {{'operator Public' is a private member}}
class Derived2 : public Base {
Private test1 ( ) { return * this ; } // expected-error {{'operator Private' is a private member}}
Public test2 ( ) { return * this ; }
} ;
Private test1 ( Derived2 & d ) { return d ; } // expected-error {{'operator Private' is a private member}}
Public test2 ( Derived2 & d ) { return d ; }
class Derived3 : private Base { / / expected - note { { constrained by private inheritance here } } \
// expected-note {{declared private here}}
public :
operator Private ( ) ;
} ;
Private test1 ( Derived3 & d ) { return d ; }
Public test2 ( Derived3 & d ) { return d ; } / / expected - error { { ' operator Public ' is a private member of ' test4 : : Base ' } } \
// expected-error {{cannot cast 'test4::Derived3' to its private base class}}
class Derived4 : public Base {
public :
operator Private ( ) ;
} ;
Private test1 ( Derived4 & d ) { return d ; }
Public test2 ( Derived4 & d ) { return d ; }
}
2010-03-16 14:11:48 +08:00
// Implicit copy assignment operator uses.
namespace test5 {
class A {
2016-09-01 07:24:08 +08:00
void operator = ( const A & ) ;
# if __cplusplus < 201103L
// expected-note@-2 2{{implicitly declared private here}}
# endif
2010-03-16 14:11:48 +08:00
} ;
2016-09-01 07:24:08 +08:00
# if __cplusplus < 201103L
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
class Test1 { A a ; } ; // expected-error {{private member}}
2010-03-16 14:11:48 +08:00
void test1 ( ) {
2011-05-11 03:08:14 +08:00
Test1 a ;
2013-06-13 11:34:55 +08:00
a = Test1 ( ) ; // expected-note{{implicit copy}}
2010-03-16 14:11:48 +08:00
}
Complete reimplementation of the synthesis for implicitly-defined copy
assignment operators.
Previously, Sema provided type-checking and template instantiation for
copy assignment operators, then CodeGen would synthesize the actual
body of the copy constructor. Unfortunately, the two were not in sync,
and CodeGen might pick a copy-assignment operator that is different
from what Sema chose, leading to strange failures, e.g., link-time
failures when CodeGen called a copy-assignment operator that was not
instantiation, run-time failures when copy-assignment operators were
overloaded for const/non-const references and the wrong one was
picked, and run-time failures when by-value copy-assignment operators
did not have their arguments properly copy-initialized.
This implementation synthesizes the implicitly-defined copy assignment
operator bodies in Sema, so that the resulting ASTs encode exactly
what CodeGen needs to do; there is no longer any special code in
CodeGen to synthesize copy-assignment operators. The synthesis of the
body is relatively simple, and we generate one of three different
kinds of copy statements for each base or member:
- For a class subobject, call the appropriate copy-assignment
operator, after overload resolution has determined what that is.
- For an array of scalar types or an array of class types that have
trivial copy assignment operators, construct a call to
__builtin_memcpy.
- For an array of class types with non-trivial copy assignment
operators, synthesize a (possibly nested!) for loop whose inner
statement calls the copy constructor.
- For a scalar type, use built-in assignment.
This patch fixes at least a few tests cases in Boost.Spirit that were
failing because CodeGen picked the wrong copy-assignment operator
(leading to link-time failures), and I suspect a number of undiagnosed
problems will also go away with this change.
Some of the diagnostics we had previously have gotten worse with this
change, since we're going through generic code for our
type-checking. I will improve this in a subsequent patch.
llvm-svn: 102853
2010-05-02 04:49:11 +08:00
class Test2 : A { } ; // expected-error {{private member}}
2010-03-16 14:11:48 +08:00
void test2 ( ) {
Test2 a ;
2013-06-13 11:34:55 +08:00
a = Test2 ( ) ; // expected-note{{implicit copy}}
2010-03-16 14:11:48 +08:00
}
2016-09-01 07:24:08 +08:00
# else
class Test1 { A a ; } ; // expected-note {{because field 'a' has an inaccessible copy assignment operator}}
void test1 ( ) {
Test1 a ;
a = Test1 ( ) ; // expected-error {{copy assignment operator is implicitly deleted}}
}
class Test2 : A { } ; // expected-note {{because base class 'test5::A' has an inaccessible copy assignment operator}}
void test2 ( ) {
Test2 a ;
a = Test2 ( ) ; // expected-error {{copy assignment operator is implicitly deleted}}
}
# endif
2010-03-16 14:11:48 +08:00
}
// Implicit copy constructor uses.
namespace test6 {
class A {
public : A ( ) ;
2016-09-01 07:24:08 +08:00
private : A ( const A & ) ;
# if __cplusplus < 201103L
// expected-note@-2 2{{declared private here}}
# endif
2010-03-16 14:11:48 +08:00
} ;
2016-09-01 07:24:08 +08:00
# if __cplusplus < 201103L
2011-05-20 07:44:42 +08:00
class Test1 { A a ; } ; // expected-error {{field of type 'test6::A' has private copy constructor}}
2010-03-16 14:11:48 +08:00
void test1 ( const Test1 & t ) {
2013-06-13 11:34:55 +08:00
Test1 a = t ; // expected-note{{implicit copy}}
2010-03-16 14:11:48 +08:00
}
2011-05-20 07:44:42 +08:00
class Test2 : A { } ; // expected-error {{base class 'test6::A' has private copy constructor}}
2010-03-16 14:11:48 +08:00
void test2 ( const Test2 & t ) {
2013-06-13 11:34:55 +08:00
Test2 a = t ; // expected-note{{implicit copy}}
2010-03-16 14:11:48 +08:00
}
2016-09-01 07:24:08 +08:00
# else
class Test1 { A a ; } ; // expected-note {{field 'a' has an inaccessible copy constructor}}
void test1 ( const Test1 & t ) {
Test1 a = t ; // expected-error{{implicitly-deleted}}
}
class Test2 : A { } ; // expected-note {{base class 'test6::A' has an inaccessible copy constructor}}
void test2 ( const Test2 & t ) {
Test2 a = t ; // expected-error{{implicitly-deleted}}
}
# endif
2010-03-16 14:11:48 +08:00
}
2010-03-18 14:42:38 +08:00
// Redeclaration lookups are not accesses.
namespace test7 {
class A {
int private_member ;
} ;
class B : A {
int foo ( int private_member ) {
return 0 ;
}
} ;
}
2010-03-18 16:19:33 +08:00
// Ignored operator new and delete overloads are not
namespace test8 {
typedef __typeof__ ( sizeof ( int ) ) size_t ;
class A {
void * operator new ( size_t s ) ;
void operator delete ( void * p ) ;
public :
void * operator new ( size_t s , int n ) ;
void operator delete ( void * p , int n ) ;
} ;
void test ( ) {
new ( 2 ) A ( ) ;
}
}
2010-03-19 07:49:19 +08:00
// Don't silently upgrade forbidden-access paths to private.
namespace test9 {
class A {
2010-05-28 12:34:55 +08:00
public : static int x ; // expected-note {{member is declared here}}
2010-03-19 07:49:19 +08:00
} ;
class B : private A { // expected-note {{constrained by private inheritance here}}
} ;
class C : public B {
static int getX ( ) { return x ; } // expected-error {{'x' is a private member of 'test9::A'}}
} ;
}
2010-03-24 17:04:37 +08:00
namespace test10 {
class A {
enum {
value = 10 // expected-note {{declared private here}}
} ;
friend class C ;
} ;
class B {
enum {
value = A : : value // expected-error {{'value' is a private member of 'test10::A'}}
} ;
} ;
class C {
enum {
value = A : : value
} ;
} ;
}
2010-03-26 06:08:03 +08:00
namespace test11 {
class A {
protected : virtual ~ A ( ) ;
} ;
class B : public A {
~ B ( ) ;
} ;
B : : ~ B ( ) { } ;
}
2010-03-27 14:55:49 +08:00
namespace test12 {
class A {
int x ;
void foo ( ) {
class Local {
int foo ( A * a ) {
return a - > x ;
}
} ;
}
} ;
}
2010-03-31 05:47:33 +08:00
namespace test13 {
struct A {
int x ;
unsigned foo ( ) const ;
} ;
struct B : protected A {
using A : : foo ;
using A : : x ;
} ;
void test ( ) {
A * d ;
d - > foo ( ) ;
( void ) d - > x ;
}
}
2010-04-07 08:41:46 +08:00
// Destructors for temporaries.
namespace test14 {
class A {
private : ~ A ( ) ; // expected-note {{declared private here}}
} ;
A foo ( ) ;
void test ( ) {
foo ( ) ; // expected-error {{temporary of type 'test14::A' has private destructor}}
}
2010-04-25 07:45:46 +08:00
class X {
~ X ( ) ; // expected-note {{declared private here}}
} ;
struct Y1 {
operator X ( ) ;
} ;
void g ( ) {
const X & xr = Y1 ( ) ; // expected-error{{temporary of type 'test14::X' has private destructor}}
}
2010-04-07 08:41:46 +08:00
}
2010-04-25 07:45:46 +08:00
2010-05-04 13:11:27 +08:00
// PR 7024
namespace test15 {
template < class T > class A {
private :
int private_foo ; // expected-note {{declared private here}}
static int private_sfoo ; // expected-note {{declared private here}}
protected :
Fix several problems with protected access control:
- The [class.protected] restriction is non-trivial for any instance
member, even if the access lacks an object (for example, if it's
a pointer-to-member constant). In this case, it is equivalent to
requiring the naming class to equal the context class.
- The [class.protected] restriction applies to accesses to constructors
and destructors. A protected constructor or destructor can only be
used to create or destroy a base subobject, as a direct result.
- Several places were dropping or misapplying object information.
The standard could really be much clearer about what the object type is
supposed to be in some of these accesses. Usually it's easy enough to
find a reasonable answer, but still, the standard makes a very confident
statement about accesses to instance members only being possible in
either pointer-to-member literals or member access expressions, which
just completely ignores concepts like constructor and destructor
calls, using declarations, unevaluated field references, etc.
llvm-svn: 154248
2012-04-07 11:04:20 +08:00
int protected_foo ; // expected-note 3 {{declared protected here}} // expected-note {{can only access this member on an object of type 'test15::B<int>'}}
2010-05-04 13:11:27 +08:00
static int protected_sfoo ; // expected-note 3 {{declared protected here}}
int test1 ( A < int > & a ) {
return a . private_foo ; // expected-error {{private member}}
}
int test2 ( A < int > & a ) {
return a . private_sfoo ; // expected-error {{private member}}
}
int test3 ( A < int > & a ) {
return a . protected_foo ; // expected-error {{protected member}}
}
int test4 ( A < int > & a ) {
return a . protected_sfoo ; // expected-error {{protected member}}
}
} ;
template class A < int > ;
template class A < long > ; // expected-note 4 {{in instantiation}}
template < class T > class B : public A < T > {
// TODO: These first two accesses can be detected as ill-formed at
// definition time because they're member accesses and A<int> can't
// be a subclass of B<T> for any T.
int test1 ( A < int > & a ) {
return a . protected_foo ; // expected-error 2 {{protected member}}
}
int test2 ( A < int > & a ) {
return a . protected_sfoo ; // expected-error {{protected member}}
}
int test3 ( B < int > & b ) {
return b . protected_foo ; // expected-error {{protected member}}
}
int test4 ( B < int > & b ) {
return b . protected_sfoo ; // expected-error {{protected member}}
}
} ;
template class B < int > ; // expected-note {{in instantiation}}
template class B < long > ; // expected-note 4 {{in instantiation}}
}
2010-06-04 04:39:03 +08:00
// PR7281
namespace test16 {
2010-07-08 14:14:04 +08:00
class A { ~ A ( ) ; } ; // expected-note 2{{declared private here}}
void b ( ) { throw A ( ) ; } / / expected - error { { temporary of type ' test16 : : A ' has private destructor } } \
// expected-error{{exception object of type 'test16::A' has private destructor}}
2010-06-04 04:39:03 +08:00
}
2010-08-13 10:23:42 +08:00
// rdar://problem/8146294
namespace test17 {
class A {
template < typename T > class Inner { } ; // expected-note {{declared private here}}
} ;
A : : Inner < int > s ; // expected-error {{'Inner' is a private member of 'test17::A'}}
}
2010-08-13 15:02:08 +08:00
namespace test18 {
template < class T > class A { } ;
class B : A < int > {
A < int > member ;
} ;
// FIXME: this access to A should be forbidden (because C++ is dumb),
// but LookupResult can't express the necessary information to do
// the check, so we aggressively suppress access control.
class C : B {
A < int > member ;
} ;
}
2010-10-13 04:32:36 +08:00
// PR8325
namespace test19 {
class A { ~ A ( ) ; } ;
// The destructor is not implicitly referenced here. Contrast to test16,
// testing PR7281, earlier in this file.
void b ( A * x ) { throw x ; }
}
2010-10-20 16:15:06 +08:00
// PR7930
namespace test20 {
class Foo {
Foo ( ) ; // expected-note {{implicitly declared private here}}
} ;
Foo : : Foo ( ) { }
void test ( ) {
Foo a ; // expected-error {{calling a private constructor}}
}
}
namespace test21 {
template < class T > class A {
void foo ( ) ;
void bar ( ) ;
class Inner ; // expected-note {{implicitly declared private here}}
public :
void baz ( ) ;
} ;
template < class T > class A < T > : : Inner { } ;
class B {
2012-03-18 07:06:31 +08:00
template < class T > class A < T > : : Inner ; // expected-error{{non-friend class member 'Inner' cannot have a qualified name}}
2010-10-20 16:15:06 +08:00
} ;
void test ( ) {
A < int > : : Inner i ; // expected-error {{'Inner' is a private member}}
}
}
2011-01-20 09:32:05 +08:00
namespace rdar8876150 {
struct A { operator bool ( ) ; } ;
struct B : private A { using A : : operator bool ; } ;
bool f ( ) {
B b ;
return ! b ;
}
}
2011-02-15 04:37:25 +08:00
namespace test23 {
template < typename T > class A {
A ( ) ;
static A instance ;
} ;
template < typename T > A < T > A < T > : : instance ;
template class A < int > ;
}