forked from llvm-mirror/clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check access to friend declarations. There's a number of different
things going on here that were problematic: - We were missing the actual access check, or rather, it was suppressed on account of being a redeclaration lookup. - The access check would naturally happen during delay, which isn't appropriate in this case. - We weren't actually emitting dependent diagnostics associated with class templates, which was unfortunate. - Access was being propagated incorrectly for friend method declarations that couldn't be matched at parse-time. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161652 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
9 changed files
with
205 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
// C++98 [class.friend]p7: | ||
// C++11 [class.friend]p9: | ||
// A name nominated by a friend declaration shall be accessible in | ||
// the scope of the class containing the friend declaration. | ||
|
||
// PR12328 | ||
// Simple, non-templated case. | ||
namespace test0 { | ||
class X { | ||
void f(); // expected-note {{implicitly declared private here}} | ||
}; | ||
|
||
class Y { | ||
friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test0::X'}} | ||
}; | ||
} | ||
|
||
// Templated but non-dependent. | ||
namespace test1 { | ||
class X { | ||
void f(); // expected-note {{implicitly declared private here}} | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test1::X'}} | ||
}; | ||
} | ||
|
||
// Dependent but instantiated at the right type. | ||
namespace test2 { | ||
template <class T> class Y; | ||
|
||
class X { | ||
void f(); | ||
friend class Y<int>; | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X::f(); | ||
}; | ||
|
||
template class Y<int>; | ||
} | ||
|
||
// Dependent and instantiated at the wrong type. | ||
namespace test3 { | ||
template <class T> class Y; | ||
|
||
class X { | ||
void f(); // expected-note {{implicitly declared private here}} | ||
friend class Y<int>; | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X::f(); // expected-error {{friend function 'f' is a private member of 'test3::X'}} | ||
}; | ||
|
||
template class Y<float>; // expected-note {{in instantiation}} | ||
} | ||
|
||
// Dependent because dependently-scoped. | ||
namespace test4 { | ||
template <class T> class X { | ||
void f(); | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X<T>::f(); | ||
}; | ||
} | ||
|
||
// Dependently-scoped, no friends. | ||
namespace test5 { | ||
template <class T> class X { | ||
void f(); // expected-note {{implicitly declared private here}} | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X<T>::f(); // expected-error {{friend function 'f' is a private member of 'test5::X<int>'}} | ||
}; | ||
|
||
template class Y<int>; // expected-note {{in instantiation}} | ||
} | ||
|
||
// Dependently-scoped, wrong friend. | ||
namespace test6 { | ||
template <class T> class Y; | ||
|
||
template <class T> class X { | ||
void f(); // expected-note {{implicitly declared private here}} | ||
friend class Y<float>; | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X<T>::f(); // expected-error {{friend function 'f' is a private member of 'test6::X<int>'}} | ||
}; | ||
|
||
template class Y<int>; // expected-note {{in instantiation}} | ||
} | ||
|
||
// Dependently-scoped, right friend. | ||
namespace test7 { | ||
template <class T> class Y; | ||
|
||
template <class T> class X { | ||
void f(); | ||
friend class Y<int>; | ||
}; | ||
|
||
template <class T> class Y { | ||
friend void X<T>::f(); | ||
}; | ||
|
||
template class Y<int>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters