[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / ms-unqualified-base-class.cpp
blob5e926c5087f9354aa8dcd7d231cb151fece34403
1 // RUN: %clang_cc1 -std=c++17 -fms-compatibility -fsyntax-only -verify=before,expected %s
2 // RUN: %clang_cc1 -std=c++17 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=before,expected %s
3 // RUN: %clang_cc1 -std=c++20 -fms-compatibility -fsyntax-only -verify=after,expected %s
4 // RUN: %clang_cc1 -std=c++20 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=after,expected %s
6 template <class T>
7 class Base {
8 };
10 template <class T>
11 class Based {}; // Trying to trick the typo detection
13 template <class T>
14 class Derived : public Base<T> {
15 public:
16 // after-error@+1 {{member initializer 'Base' does not name a non-static data member or base class}}
17 Derived() : Base() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
18 private:
19 int Baze; // Trying to trick the typo detection
22 template <class T> struct AggregateBase {
23 T i;
26 template <class T>
27 struct AggregateDerived : public AggregateBase<T> {
28 int i;
30 // after-error@+1 {{member initializer 'AggregateBase' does not name a non-static data member or base class}}
31 AggregateDerived(T j) : AggregateBase{4}, i{j} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
32 int f() {
33 return i + AggregateBase::i; // expected-warning {{use of undeclared identifier 'AggregateBase'; unqualified lookup into dependent bases of class template 'AggregateDerived' is a Microsoft extension}}
37 template <class T, typename U> struct MultiTypesBase {
40 template <class T, class U>
41 struct MultiTypesDerived : public MultiTypesBase<T, U> {
42 // after-error@+1 {{member initializer 'MultiTypesBase' does not name a non-static data member or base class}}
43 MultiTypesDerived() : MultiTypesBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
46 template <int I> struct IntegerBase {
49 template <int I>
50 struct IntegerDerived : public IntegerBase<I> {
51 // after-error@+1 {{member initializer 'IntegerBase' does not name a non-static data member or base class}}
52 IntegerDerived() : IntegerBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
55 template <class T> struct ConformingBase {
56 T i;
59 template <class T>
60 struct ConformingDerived : public ConformingBase<T> {
61 int i;
63 ConformingDerived(T j) : ConformingBase<T>{4}, i{j} {}
64 int f() {
65 return i + ConformingBase<T>::i;
69 int main() {
70 int I;
71 Derived<int> t;
73 AggregateDerived<int> AD{2};
74 AD.AggregateBase::i = 3;
75 I = AD.f();
77 MultiTypesDerived<int, double> MTD;
79 IntegerDerived<4> ID;
81 ConformingDerived<int> CD{2};
82 I = CD.f();
84 return I;
87 template <typename Type, int TSize> class Vec {}; // expected-note {{template is declared here}}
89 template <int TDim> class Index : public Vec<int, TDim> {
90 // after-error@+1 {{member initializer 'Vec' does not name a non-static data member or base class}}
91 Index() : Vec() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
94 template class Index<0>;
96 template <typename T> class Array : public Vec<T, 4> {
97 // after-error@+1 {{member initializer 'Vec' does not name a non-static data member or base class}}
98 Array() : Vec() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
101 template class Array<double>;
103 template <typename T> class Wrong : public Vec<T, 4> {
104 Wrong() : NonExistent() {} // expected-error {{member initializer 'NonExistent' does not name a non-static data member or base class}}
107 template class Wrong<double>;
109 template <typename T> class Wrong2 : public Vec<T, 4> {
110 Wrong2() : Vec<T>() {} // expected-error {{too few template arguments for class template 'Vec'}}
113 template class Wrong2<double>;
115 template <typename T> class Wrong3 : public Vec<T, 4> {
116 Wrong3() : Base() {} // expected-error {{member initializer 'Base' does not name a non-static data member or base class}}
119 template class Wrong3<double>;