[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / test / SemaCXX / ms-constexpr-invalid.cpp
blobe5bec0c7119b02871681e5a8465ce7815689af46
1 // RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s
2 // RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++17 -verify %s
4 // Check explicitly invalid code
6 void runtime() {} // expected-note {{declared here}}
8 [[msvc::constexpr]] void f0() { runtime(); } // expected-error {{constexpr function never produces a constant expression}} \
9 // expected-note {{non-constexpr function 'runtime' cannot be used in a constant expression}}
10 [[msvc::constexpr]] constexpr void f1() {} // expected-error {{attribute 'msvc::constexpr' cannot be applied to the constexpr function 'f1'}}
11 #if __cplusplus >= 202202L
12 [[msvc::constexpr]] consteval void f2() {} // expected-error {{attribute 'msvc::constexpr' cannot be applied to the consteval function 'f1'}}
13 #endif
15 struct B1 {};
16 struct D1 : virtual B1 { // expected-note {{virtual base class declared here}}
17 [[msvc::constexpr]] D1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}}
20 struct [[msvc::constexpr]] S2{}; // expected-error {{'constexpr' attribute only applies to functions and return statements}}
22 // Check invalid code mixed with valid code
24 [[msvc::constexpr]] int f4(int x) { return x > 1 ? 1 + f4(x / 2) : 0; } // expected-note {{non-constexpr function 'f4' cannot be used in a constant expression}} \
25 // expected-note {{declared here}} \
26 // expected-note {{declared here}} \
27 // expected-note {{declared here}}
28 constexpr bool f5() { [[msvc::constexpr]] return f4(32) == 5; } // expected-note {{in call to 'f4(32)'}}
29 static_assert(f5()); // expected-error {{static assertion expression is not an integral constant expression}} \
30 // expected-note {{in call to 'f5()'}}
32 int f6(int x) { [[msvc::constexpr]] return x > 1 ? 1 + f6(x / 2) : 0; } // expected-note {{declared here}} \
33 // expected-note {{declared here}}
34 constexpr bool f7() { [[msvc::constexpr]] return f6(32) == 5; } // expected-error {{constexpr function never produces a constant expression}} \
35 // expected-note {{non-constexpr function 'f6' cannot be used in a constant expression}} \
36 // expected-note {{non-constexpr function 'f6' cannot be used in a constant expression}}
37 static_assert(f7()); // expected-error {{static assertion expression is not an integral constant expression}} \
38 // expected-note {{in call to 'f7()'}}
40 constexpr bool f8() { // expected-error {{constexpr function never produces a constant expression}}
41 [[msvc::constexpr]] f4(32); // expected-error {{'constexpr' attribute only applies to functions and return statements}} \
42 // expected-note {{non-constexpr function 'f4' cannot be used in a constant expression}} \
43 // expected-note {{non-constexpr function 'f4' cannot be used in a constant expression}}
44 [[msvc::constexpr]] int i5 = f4(32); // expected-error {{'constexpr' attribute only applies to functions and return statements}}
45 return i5 == 5;
47 static_assert(f8()); // expected-error {{static assertion expression is not an integral constant expression}} \
48 // expected-note {{in call to 'f8()'}}
50 #if __cplusplus == 201702L
51 struct S1 { [[msvc::constexpr]] virtual bool vm() const { return true; } }; // expected-error {{attribute 'msvc::constexpr' ignored, it only applies to function definitions and return statements}}
52 #endif