File: ms-unqualified-base-class.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (119 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// RUN: %clang_cc1 -std=c++17 -fms-compatibility -fsyntax-only -verify=before,expected %s
// RUN: %clang_cc1 -std=c++17 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=before,expected %s
// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fsyntax-only -verify=after,expected %s
// RUN: %clang_cc1 -std=c++20 -fms-compatibility -fdelayed-template-parsing -fsyntax-only -verify=after,expected %s

template <class T>
class Base {
};

template <class T>
class Based {}; // Trying to trick the typo detection

template <class T>
class Derived : public Base<T> {
public:
  // after-error@+1 {{member initializer 'Base' does not name a non-static data member or base class}}
  Derived() : Base() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
private:
  int Baze; // Trying to trick the typo detection
};

template <class T> struct AggregateBase {
  T i;
};

template <class T>
struct AggregateDerived : public AggregateBase<T> {
  int i;

  // after-error@+1 {{member initializer 'AggregateBase' does not name a non-static data member or base class}}
  AggregateDerived(T j) : AggregateBase{4}, i{j} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
  int f() {
    return i + AggregateBase::i; // expected-warning {{use of undeclared identifier 'AggregateBase'; unqualified lookup into dependent bases of class template 'AggregateDerived' is a Microsoft extension}}
  }
};

template <class T, typename U> struct MultiTypesBase {
};

template <class T, class U>
struct MultiTypesDerived : public MultiTypesBase<T, U> {
  // after-error@+1 {{member initializer 'MultiTypesBase' does not name a non-static data member or base class}}
  MultiTypesDerived() : MultiTypesBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
};

template <int I> struct IntegerBase {
};

template <int I>
struct IntegerDerived : public IntegerBase<I> {
  // after-error@+1 {{member initializer 'IntegerBase' does not name a non-static data member or base class}}
  IntegerDerived() : IntegerBase{} {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
};

template <class T> struct ConformingBase {
  T i;
};

template <class T>
struct ConformingDerived : public ConformingBase<T> {
  int i;

  ConformingDerived(T j) : ConformingBase<T>{4}, i{j} {}
  int f() {
    return i + ConformingBase<T>::i;
  }
};

int main() {
  int I;
  Derived<int> t;

  AggregateDerived<int> AD{2};
  AD.AggregateBase::i = 3;
  I = AD.f();

  MultiTypesDerived<int, double> MTD;

  IntegerDerived<4> ID;

  ConformingDerived<int> CD{2};
  I = CD.f();

  return I;
}

template <typename Type, int TSize> class Vec {}; // expected-note {{template is declared here}}

template <int TDim> class Index : public Vec<int, TDim> {
  // after-error@+1 {{member initializer 'Vec' does not name a non-static data member or base class}}
  Index() : Vec() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
};

template class Index<0>;

template <typename T> class Array : public Vec<T, 4> {
  // after-error@+1 {{member initializer 'Vec' does not name a non-static data member or base class}}
  Array() : Vec() {} // before-warning {{unqualified base initializer of class templates is a Microsoft extension}}
};

template class Array<double>;

template <typename T> class Wrong : public Vec<T, 4> {
  Wrong() : NonExistent() {} // expected-error {{member initializer 'NonExistent' does not name a non-static data member or base class}}
};

template class Wrong<double>;

template <typename T> class Wrong2 : public Vec<T, 4> {
  Wrong2() : Vec<T>() {} // expected-error {{too few template arguments for class template 'Vec'}}
};

template class Wrong2<double>;

template <typename T> class Wrong3 : public Vec<T, 4> {
  Wrong3() : Base() {} // expected-error {{member initializer 'Base' does not name a non-static data member or base class}}
};

template class Wrong3<double>;