116 lines · cpp
1// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -Wno-microsoft -std=c++112 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-re@+1 {{nested class I1::(unnamed struct at {{.*}}) is not permitted within an interface type}}14 struct { int a; };15 void fn2() {16 struct A { }; // should be ignored: not a nested class17 }18protected: // expected-error {{interface types cannot specify 'protected' access}}19 typedef void void_t;20 using int_t = int;21private: // 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();30private: // 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();33protected: // 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();36public: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 54template <typename X>55__interface I6 : X {56};57 58struct S { };59class C { };60__interface I { };61union U;62 63static_assert(!__is_interface_class(S), "oops");64static_assert(!__is_interface_class(C), "oops");65static_assert(!__is_interface_class(I), "oops");66static_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}}70struct 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}}75class C1 : I6<C> {76};77 78class C2 : I6<I> {79};80 81 82// MSVC makes a special case in that an interface is allowed to have a data83// 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 90struct __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 98struct 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 {};105static_assert(!__is_interface_class(HasProp), "oops");106static_assert(!__is_interface_class(IUnknown), "oops");107static_assert(!__is_interface_class(IFaceStruct), "oops");108static_assert(!__is_interface_class(IFaceInheritsStruct), "oops");109 110template<typename>111class TemplateContext {112 class Base;113 // Should not crash on an incomplete-type and dependent base specifier.114 __interface Foo : Base {};115};116