[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / test / SemaCXX / ms-constexpr.cpp
blob79f71a34cb7d8485b1f95cdd34c8798bfa7e0f4b
1 // RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s
3 [[msvc::constexpr]] int log2(int x) { [[msvc::constexpr]] return x > 1 ? 1 + log2(x / 2) : 0; }
4 constexpr bool test_log2() { [[msvc::constexpr]] return log2(32) == 5; }
5 static_assert(test_log2());
7 [[msvc::constexpr]] int get_value(int x)
9 switch (x)
11 case 42: return 1337;
12 default:
13 if (x < 0) [[msvc::constexpr]] return log2(-x);
14 else return x;
18 constexpr bool test_complex_expr() {
19 [[msvc::constexpr]] return get_value(get_value(42) - 1337 + get_value(-32) - 5 + (get_value(1) ? get_value(0) : get_value(2))) == get_value(0);
21 static_assert(test_complex_expr());
23 constexpr bool get_constexpr_true() { return true; }
24 [[msvc::constexpr]] bool get_msconstexpr_true() { return get_constexpr_true(); }
25 constexpr bool test_get_msconstexpr_true() { [[msvc::constexpr]] return get_msconstexpr_true(); }
26 static_assert(test_get_msconstexpr_true());
28 // TODO (#72149): Add support for [[msvc::constexpr]] constructor; this code is valid for MSVC.
29 struct S2 {
30 [[msvc::constexpr]] S2() {}
31 [[msvc::constexpr]] bool value() { return true; }
32 static constexpr bool check() { [[msvc::constexpr]] return S2{}.value(); } // expected-error {{constexpr function never produces a constant expression}} \
33 // expected-note {{non-literal type 'S2' cannot be used in a constant expression}} \
34 // expected-note {{non-literal type 'S2' cannot be used in a constant expression}}
36 static_assert(S2::check()); // expected-error {{static assertion expression is not an integral constant expression}} \
37 // expected-note {{in call to 'check()'}}