1 // RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -Wno-microsoft -std=c++11
2 
3 __interface I1 {
4   // expected-error@+1 {{user-declared constructor is not permitted within an interface type}}
5   I1();
6   // expected-error@+1 {{user-declared destructor is not permitted within an interface type}}
7   ~I1();
8   virtual void fn1() const;
9   // expected-error@+1 {{operator 'operator!' is not permitted within an interface type}}
10   bool operator!();
11   // expected-error@+1 {{operator 'operator int' is not permitted within an interface type}}
12   operator int();
13   // expected-error@+1 {{nested class I1::(anonymous) is not permitted within an interface type}}
14   struct { int a; };
15   void fn2() {
16     struct A { }; // should be ignored: not a nested class
17   }
18 protected: // expected-error {{interface types cannot specify 'protected' access}}
19   typedef void void_t;
20   using int_t = int;
21 private:   // expected-error {{interface types cannot specify 'private' access}}
22   static_assert(true, "oops");
23 };
24 
25 __interface I2 {
26   // expected-error@+1 {{data member 'i' is not permitted within an interface type}}
27   int i;
28   // expected-error@+1 {{static member function 'fn1' is not permitted within an interface type}}
29   static int fn1();
30 private:   // expected-error {{interface types cannot specify 'private' access}}
31   // expected-error@+1 {{non-public member function 'fn2' is not permitted within an interface type}}
32   void fn2();
33 protected: // expected-error {{interface types cannot specify 'protected' access}}
34   // expected-error@+1 {{non-public member function 'fn3' is not permitted within an interface type}}
35   void fn3();
36 public:
37   void fn4();
38 };
39 
40 // expected-error@+1 {{'final' keyword not permitted with interface types}}
41 __interface I3 final {
42 };
43 
44 __interface I4 : I1, I2 {
45   void fn1() const override;
46   // expected-error@+1 {{'final' keyword not permitted with interface types}}
47   void fn2() final;
48 };
49 
50 // expected-error@+1 {{interface type cannot inherit from non-public interface 'I1'}}
51 __interface I5 : private I1 {
52 };
53 
54 template <typename X>
55 __interface I6 : X {
56 };
57 
58 struct S { };
59 class C { };
60 __interface I { };
61 union U;
62 
63 static_assert(!__is_interface_class(S), "oops");
64 static_assert(!__is_interface_class(C), "oops");
65 static_assert(!__is_interface_class(I), "oops");
66 static_assert(!__is_interface_class(U), "oops");
67 
68 // expected-error@55 {{interface type cannot inherit from struct 'S'}}
69 // expected-note@+1 {{in instantiation of template class 'I6<S>' requested here}}
70 struct S1 : I6<S> {
71 };
72 
73 // expected-error@55 {{interface type cannot inherit from class 'C'}}
74 // expected-note@+1 {{in instantiation of template class 'I6<C>' requested here}}
75 class C1 : I6<C> {
76 };
77 
78 class C2 : I6<I> {
79 };
80 
81 
82 // MSVC makes a special case in that an interface is allowed to have a data
83 // member if it is a property.
84 __interface HasProp {
85   __declspec(property(get = Get, put = Put)) int data;
86   int Get(void);
87   void Put(int);
88 };
89 
90 struct __declspec(uuid("00000000-0000-0000-C000-000000000046"))
91     IUnknown {
92   void foo();
93   __declspec(property(get = Get, put = Put), deprecated) int data;
94   int Get(void);
95   void Put(int);
96 };
97 
98 struct IFaceStruct : IUnknown {
99   __declspec(property(get = Get2, put = Put2), deprecated) int data2;
100   int Get2(void);
101   void Put2(int);
102 };
103 
104 __interface IFaceInheritsStruct : IFaceStruct {};
105 static_assert(!__is_interface_class(HasProp), "oops");
106 static_assert(!__is_interface_class(IUnknown), "oops");
107 static_assert(!__is_interface_class(IFaceStruct), "oops");
108 static_assert(!__is_interface_class(IFaceInheritsStruct), "oops");
109