xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/MicrosoftSuper.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -fsyntax-only -fms-extensions -std=c++11 -verify
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc struct Errors {
4*0a6a1f1dSLionel Sambuc   using __super::foo; // expected-error {{'__super' cannot be used with a using declaration}}
5*0a6a1f1dSLionel Sambuc   __super::XXX x; // expected-error {{invalid use of '__super', Errors has no base classes}} expected-error {{expected}}
6*0a6a1f1dSLionel Sambuc 
fooErrors7*0a6a1f1dSLionel Sambuc   void foo() {
8*0a6a1f1dSLionel Sambuc     // expected-note@+4 {{replace parentheses with an initializer to declare a variable}}
9*0a6a1f1dSLionel Sambuc     // expected-warning@+3 {{empty parentheses interpreted as a function declaration}}
10*0a6a1f1dSLionel Sambuc     // expected-error@+2 {{C++ requires a type specifier for all declarations}}
11*0a6a1f1dSLionel Sambuc     // expected-error@+1 {{use of '__super' inside a lambda is unsupported}}
12*0a6a1f1dSLionel Sambuc     auto lambda = []{ __super::foo(); };
13*0a6a1f1dSLionel Sambuc   }
14*0a6a1f1dSLionel Sambuc };
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc struct Base1 {
fooBase117*0a6a1f1dSLionel Sambuc   void foo(int) {}
18*0a6a1f1dSLionel Sambuc 
static_fooBase119*0a6a1f1dSLionel Sambuc   static void static_foo() {}
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc   typedef int XXX;
22*0a6a1f1dSLionel Sambuc };
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc struct Derived : Base1 {
25*0a6a1f1dSLionel Sambuc   __super::XXX x;
26*0a6a1f1dSLionel Sambuc   typedef __super::XXX Type;
27*0a6a1f1dSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc   enum E {
29*0a6a1f1dSLionel Sambuc     X = sizeof(__super::XXX)
30*0a6a1f1dSLionel Sambuc   };
31*0a6a1f1dSLionel Sambuc 
fooDerived32*0a6a1f1dSLionel Sambuc   void foo() {
33*0a6a1f1dSLionel Sambuc     __super::foo(1);
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc     if (true) {
36*0a6a1f1dSLionel Sambuc       __super::foo(1);
37*0a6a1f1dSLionel Sambuc     }
38*0a6a1f1dSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc     return __super::foo(1);
40*0a6a1f1dSLionel Sambuc   }
41*0a6a1f1dSLionel Sambuc 
barDerived42*0a6a1f1dSLionel Sambuc   static void bar() {
43*0a6a1f1dSLionel Sambuc     __super::static_foo();
44*0a6a1f1dSLionel Sambuc   }
45*0a6a1f1dSLionel Sambuc };
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc struct Outer {
48*0a6a1f1dSLionel Sambuc   struct Inner : Base1 {
49*0a6a1f1dSLionel Sambuc     static const int x = sizeof(__super::XXX);
50*0a6a1f1dSLionel Sambuc   };
51*0a6a1f1dSLionel Sambuc };
52*0a6a1f1dSLionel Sambuc 
53*0a6a1f1dSLionel Sambuc struct Base2 {
fooBase254*0a6a1f1dSLionel Sambuc   void foo(char) {}
55*0a6a1f1dSLionel Sambuc };
56*0a6a1f1dSLionel Sambuc 
57*0a6a1f1dSLionel Sambuc struct MemberFunctionInMultipleBases : Base1, Base2 {
fooMemberFunctionInMultipleBases58*0a6a1f1dSLionel Sambuc   void foo() {
59*0a6a1f1dSLionel Sambuc     __super::foo('x');
60*0a6a1f1dSLionel Sambuc   }
61*0a6a1f1dSLionel Sambuc };
62*0a6a1f1dSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc struct Base3 {
fooBase364*0a6a1f1dSLionel Sambuc   void foo(int) {}
fooBase365*0a6a1f1dSLionel Sambuc   void foo(char) {}
66*0a6a1f1dSLionel Sambuc };
67*0a6a1f1dSLionel Sambuc 
68*0a6a1f1dSLionel Sambuc struct OverloadedMemberFunction : Base3 {
fooOverloadedMemberFunction69*0a6a1f1dSLionel Sambuc   void foo() {
70*0a6a1f1dSLionel Sambuc     __super::foo('x');
71*0a6a1f1dSLionel Sambuc   }
72*0a6a1f1dSLionel Sambuc };
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc struct PointerToMember : Base1 {
75*0a6a1f1dSLionel Sambuc   template <void (Base1::*MP)(int)>
76*0a6a1f1dSLionel Sambuc   struct Wrapper {
barPointerToMember::Wrapper77*0a6a1f1dSLionel Sambuc     static void bar() {}
78*0a6a1f1dSLionel Sambuc   };
79*0a6a1f1dSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc   void baz();
81*0a6a1f1dSLionel Sambuc };
82*0a6a1f1dSLionel Sambuc 
baz()83*0a6a1f1dSLionel Sambuc void PointerToMember::baz() {
84*0a6a1f1dSLionel Sambuc   Wrapper<&__super::foo>::bar();
85*0a6a1f1dSLionel Sambuc }
86*0a6a1f1dSLionel Sambuc 
87*0a6a1f1dSLionel Sambuc template <typename T>
88*0a6a1f1dSLionel Sambuc struct BaseTemplate {
89*0a6a1f1dSLionel Sambuc   typedef int XXX;
90*0a6a1f1dSLionel Sambuc 
fooBaseTemplate91*0a6a1f1dSLionel Sambuc   int foo() { return 0; }
92*0a6a1f1dSLionel Sambuc };
93*0a6a1f1dSLionel Sambuc 
94*0a6a1f1dSLionel Sambuc struct DerivedFromKnownSpecialization : BaseTemplate<int> {
95*0a6a1f1dSLionel Sambuc   __super::XXX a;
96*0a6a1f1dSLionel Sambuc   typedef __super::XXX b;
97*0a6a1f1dSLionel Sambuc 
fooDerivedFromKnownSpecialization98*0a6a1f1dSLionel Sambuc   void foo() {
99*0a6a1f1dSLionel Sambuc     __super::XXX c;
100*0a6a1f1dSLionel Sambuc     typedef __super::XXX d;
101*0a6a1f1dSLionel Sambuc 
102*0a6a1f1dSLionel Sambuc     __super::foo();
103*0a6a1f1dSLionel Sambuc   }
104*0a6a1f1dSLionel Sambuc };
105*0a6a1f1dSLionel Sambuc 
106*0a6a1f1dSLionel Sambuc template <typename T>
107*0a6a1f1dSLionel Sambuc struct DerivedFromDependentBase : BaseTemplate<T> {
108*0a6a1f1dSLionel Sambuc   typename __super::XXX a;
109*0a6a1f1dSLionel Sambuc   typedef typename __super::XXX b;
110*0a6a1f1dSLionel Sambuc 
111*0a6a1f1dSLionel Sambuc   __super::XXX c;         // expected-error {{missing 'typename'}}
112*0a6a1f1dSLionel Sambuc   typedef __super::XXX d; // expected-error {{missing 'typename'}}
113*0a6a1f1dSLionel Sambuc 
fooDerivedFromDependentBase114*0a6a1f1dSLionel Sambuc   void foo() {
115*0a6a1f1dSLionel Sambuc     typename __super::XXX e;
116*0a6a1f1dSLionel Sambuc     typedef typename __super::XXX f;
117*0a6a1f1dSLionel Sambuc 
118*0a6a1f1dSLionel Sambuc     __super::XXX g;         // expected-error {{missing 'typename'}}
119*0a6a1f1dSLionel Sambuc     typedef __super::XXX h; // expected-error {{missing 'typename'}}
120*0a6a1f1dSLionel Sambuc 
121*0a6a1f1dSLionel Sambuc     int x = __super::foo();
122*0a6a1f1dSLionel Sambuc   }
123*0a6a1f1dSLionel Sambuc };
124*0a6a1f1dSLionel Sambuc 
125*0a6a1f1dSLionel Sambuc template <typename T>
126*0a6a1f1dSLionel Sambuc struct DerivedFromTemplateParameter : T {
127*0a6a1f1dSLionel Sambuc   typename __super::XXX a;
128*0a6a1f1dSLionel Sambuc   typedef typename __super::XXX b;
129*0a6a1f1dSLionel Sambuc 
130*0a6a1f1dSLionel Sambuc   __super::XXX c;         // expected-error {{missing 'typename'}}
131*0a6a1f1dSLionel Sambuc   typedef __super::XXX d; // expected-error {{missing 'typename'}}
132*0a6a1f1dSLionel Sambuc 
fooDerivedFromTemplateParameter133*0a6a1f1dSLionel Sambuc   void foo() {
134*0a6a1f1dSLionel Sambuc     typename __super::XXX e;
135*0a6a1f1dSLionel Sambuc     typedef typename __super::XXX f;
136*0a6a1f1dSLionel Sambuc 
137*0a6a1f1dSLionel Sambuc     __super::XXX g;         // expected-error {{missing 'typename'}}
138*0a6a1f1dSLionel Sambuc     typedef __super::XXX h; // expected-error {{missing 'typename'}}
139*0a6a1f1dSLionel Sambuc 
140*0a6a1f1dSLionel Sambuc     __super::foo(1);
141*0a6a1f1dSLionel Sambuc   }
142*0a6a1f1dSLionel Sambuc };
143*0a6a1f1dSLionel Sambuc 
instantiate()144*0a6a1f1dSLionel Sambuc void instantiate() {
145*0a6a1f1dSLionel Sambuc   DerivedFromDependentBase<int> d;
146*0a6a1f1dSLionel Sambuc   d.foo();
147*0a6a1f1dSLionel Sambuc   DerivedFromTemplateParameter<Base1> t;
148*0a6a1f1dSLionel Sambuc   t.foo();
149*0a6a1f1dSLionel Sambuc }
150