summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2014-12-17 23:40:46 +0000
committerReid Kleckner <reid@kleckner.net>2014-12-17 23:40:46 +0000
commitaf9bf59ba901e4a6367fb262454557d1edc27e93 (patch)
tree16e0ac6fd2c5174c01ba94a891b8fc4c5a70983a /clang/test
parent969902b43b0c028d49dba8ee0b443351fa0453cb (diff)
downloadbcm5719-llvm-af9bf59ba901e4a6367fb262454557d1edc27e93.tar.gz
bcm5719-llvm-af9bf59ba901e4a6367fb262454557d1edc27e93.zip
Don't assume friended C++ method decls have qualifiers
There are a few cases where unqualified lookup can find C++ methods. Unfortunately, none of them seem to have illegal access paths, so I can't excercise the diagnostic source range code that I am changing here. Fixes PR21851, which was a crash on valid. llvm-svn: 224471
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaCXX/friend.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/clang/test/SemaCXX/friend.cpp b/clang/test/SemaCXX/friend.cpp
index 03589101e1b..55aa069803b 100644
--- a/clang/test/SemaCXX/friend.cpp
+++ b/clang/test/SemaCXX/friend.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++14
friend class A; // expected-error {{'friend' used outside of class}}
void f() { friend class A; } // expected-error {{'friend' used outside of class}}
@@ -296,3 +296,56 @@ namespace test11 {
friend class __attribute__((visibility("hidden"), noreturn)) B; // expected-warning {{'noreturn' attribute only applies to functions and methods}}
};
}
+
+namespace pr21851 {
+// PR21851 was a problem where we assumed that when the friend function redecl
+// lookup found a C++ method, it would necessarily have a qualifier. Below we
+// have some test cases where unqualified lookup finds C++ methods without using
+// qualifiers. Unfortunately, we can't exercise the case of an access check
+// failure because nested classes always have access to the members of outer
+// classes.
+
+void friend_own_method() {
+ class A {
+ void m() {}
+ friend void m();
+ };
+}
+
+void friend_enclosing_method() {
+ class A;
+ class C {
+ int p;
+ friend class A;
+ };
+ class A {
+ void enclosing_friend() {
+ (void)b->p;
+ (void)c->p;
+ }
+ class B {
+ void b(A *a) {
+ (void)a->c->p;
+ }
+ int p;
+ friend void enclosing_friend();
+ };
+ B *b;
+ C *c;
+ };
+}
+
+static auto friend_file_func() {
+ extern void file_scope_friend();
+ class A {
+ int p;
+ friend void file_scope_friend();
+ };
+ return A();
+}
+
+void file_scope_friend() {
+ auto a = friend_file_func();
+ (void)a.p;
+}
+}
OpenPOWER on IntegriCloud