1*67e74705SXin Li // RUN: %clang_cc1 %s -triple i686-pc-win32 -std=c++11 -Wmicrosoft -fms-compatibility -verify 2*67e74705SXin Li // RUN: not %clang_cc1 %s -triple i686-pc-win32 -std=c++11 -Wmicrosoft -fms-compatibility -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s 3*67e74705SXin Li 4*67e74705SXin Li struct X; 5*67e74705SXin Li namespace name_at_tu_scope { 6*67e74705SXin Li struct Y { 7*67e74705SXin Li friend struct X; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}} 8*67e74705SXin Li // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"::" 9*67e74705SXin Li }; 10*67e74705SXin Li } 11*67e74705SXin Li 12*67e74705SXin Li namespace enclosing_friend_decl { 13*67e74705SXin Li struct B; 14*67e74705SXin Li namespace ns { 15*67e74705SXin Li struct A { 16*67e74705SXin Li friend struct B; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}} 17*67e74705SXin Li // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"enclosing_friend_decl::" 18*67e74705SXin Li protected: 19*67e74705SXin Li A(); 20*67e74705SXin Li }; 21*67e74705SXin Li } 22*67e74705SXin Li struct B { fenclosing_friend_decl::B23*67e74705SXin Li static void f() { ns::A x; } 24*67e74705SXin Li }; 25*67e74705SXin Li } 26*67e74705SXin Li 27*67e74705SXin Li namespace enclosing_friend_qualified { 28*67e74705SXin Li struct B; 29*67e74705SXin Li namespace ns { 30*67e74705SXin Li struct A { 31*67e74705SXin Li friend struct enclosing_friend_qualified::B; // Adding name specifiers fixes it. 32*67e74705SXin Li protected: 33*67e74705SXin Li A(); 34*67e74705SXin Li }; 35*67e74705SXin Li } 36*67e74705SXin Li struct B { fenclosing_friend_qualified::B37*67e74705SXin Li static void f() { ns::A x; } 38*67e74705SXin Li }; 39*67e74705SXin Li } 40*67e74705SXin Li 41*67e74705SXin Li namespace enclosing_friend_no_tag { 42*67e74705SXin Li struct B; 43*67e74705SXin Li namespace ns { 44*67e74705SXin Li struct A { 45*67e74705SXin Li friend B; // Removing the tag decl fixes it. 46*67e74705SXin Li protected: 47*67e74705SXin Li A(); 48*67e74705SXin Li }; 49*67e74705SXin Li } 50*67e74705SXin Li struct B { fenclosing_friend_no_tag::B51*67e74705SXin Li static void f() { ns::A x; } 52*67e74705SXin Li }; 53*67e74705SXin Li } 54*67e74705SXin Li 55*67e74705SXin Li namespace enclosing_friend_func { 56*67e74705SXin Li void f(); 57*67e74705SXin Li namespace ns { 58*67e74705SXin Li struct A { 59*67e74705SXin Li // Amusingly, in MSVC, this declares ns::f(), and doesn't find the outer f(). 60*67e74705SXin Li friend void f(); 61*67e74705SXin Li protected: 62*67e74705SXin Li A(); // expected-note {{declared protected here}} 63*67e74705SXin Li }; 64*67e74705SXin Li } f()65*67e74705SXin Livoid f() { ns::A x; } // expected-error {{calling a protected constructor of class 'enclosing_friend_func::ns::A'}} 66*67e74705SXin Li } 67*67e74705SXin Li 68*67e74705SXin Li namespace test_nns_fixit_hint { 69*67e74705SXin Li namespace name1 { 70*67e74705SXin Li namespace name2 { 71*67e74705SXin Li struct X; 72*67e74705SXin Li struct name2; 73*67e74705SXin Li namespace name3 { 74*67e74705SXin Li struct Y { 75*67e74705SXin Li friend struct X; // expected-warning-re {{unqualified friend declaration {{.*}} is a Microsoft extension}} 76*67e74705SXin Li // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:17-[[@LINE-1]]:17}:"name1::name2::" 77*67e74705SXin Li }; 78*67e74705SXin Li } 79*67e74705SXin Li } 80*67e74705SXin Li } 81*67e74705SXin Li } 82*67e74705SXin Li 83*67e74705SXin Li // A friend declaration injects a forward declaration into the nearest enclosing 84*67e74705SXin Li // non-member scope. 85*67e74705SXin Li namespace friend_as_a_forward_decl { 86*67e74705SXin Li 87*67e74705SXin Li class A { 88*67e74705SXin Li class Nested { 89*67e74705SXin Li friend class B; 90*67e74705SXin Li B *b; 91*67e74705SXin Li }; 92*67e74705SXin Li B *b; 93*67e74705SXin Li }; 94*67e74705SXin Li B *global_b; 95*67e74705SXin Li f()96*67e74705SXin Livoid f() { 97*67e74705SXin Li class Local { 98*67e74705SXin Li friend class Z; 99*67e74705SXin Li Z *b; 100*67e74705SXin Li }; 101*67e74705SXin Li Z *b; 102*67e74705SXin Li } 103*67e74705SXin Li 104*67e74705SXin Li } 105