[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / new-array-size-conv.cpp
blob48aa015cd2978ce8e56fc969c0d2fcfacc54b4bb
1 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify -std=gnu++98 %s
2 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -pedantic -verify -std=c++11 %s
5 struct ValueInt
7 ValueInt(int v = 0) : ValueLength(v) {}
8 operator int () const { return ValueLength; } // expected-note 3{{conversion to integral type 'int' declared here}}
9 private:
10 int ValueLength;
13 enum E { e };
14 struct ValueEnum {
15 operator E() const; // expected-note{{conversion to enumeration type 'E' declared here}}
18 struct ValueBoth : ValueInt, ValueEnum { };
20 struct IndirectValueInt : ValueInt { };
21 struct TwoValueInts : ValueInt, IndirectValueInt { }; // expected-warning{{direct base 'ValueInt' is inaccessible due to ambiguity:\n struct TwoValueInts -> ValueInt\n struct TwoValueInts -> IndirectValueInt -> ValueInt}}
24 void test() {
25 (void)new int[ValueInt(10)];
26 #if __cplusplus <= 199711L // C++03 or earlier modes
27 // expected-warning@-2{{implicit conversion from array size expression of type 'ValueInt' to integral type 'int' is a C++11 extension}}
28 #endif
30 (void)new int[ValueEnum()];
31 #if __cplusplus <= 199711L
32 // expected-warning@-2{{implicit conversion from array size expression of type 'ValueEnum' to enumeration type 'E' is a C++11 extension}}
33 #endif
34 (void)new int[ValueBoth()]; // expected-error{{ambiguous conversion of array size expression of type 'ValueBoth' to an integral or enumeration type}}
36 (void)new int[TwoValueInts()]; // expected-error{{ambiguous conversion of array size expression of type 'TwoValueInts' to an integral or enumeration type}}