[SLP] Make getSameOpcode support different instructions if they have same semantics...
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.const.eval / is_constant_evaluated.pass.cpp
blob832fda32975c2ec988feb68910c7cc77a69360e2
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // <type_traits>
13 // constexpr bool is_constant_evaluated() noexcept; // C++20
15 #include <type_traits>
16 #include <cassert>
18 #include "test_macros.h"
20 #ifndef __cpp_lib_is_constant_evaluated
21 #if TEST_HAS_BUILTIN(__builtin_is_constant_evaluated)
22 # error __cpp_lib_is_constant_evaluated should be defined
23 #endif
24 #endif
26 // Disable the tautological constant evaluation warnings for this test,
27 // because it's explicitly testing those cases.
28 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wconstant-evaluated")
29 TEST_MSVC_DIAGNOSTIC_IGNORED(5063)
31 template <bool> struct InTemplate {};
33 int main(int, char**)
35 // Test the signature
37 ASSERT_SAME_TYPE(decltype(std::is_constant_evaluated()), bool);
38 ASSERT_NOEXCEPT(std::is_constant_evaluated());
39 constexpr bool p = std::is_constant_evaluated();
40 assert(p);
42 // Test the return value of the builtin for basic sanity only. It's the
43 // compiler's job to test the builtin for correctness.
45 static_assert(std::is_constant_evaluated(), "");
46 bool p = std::is_constant_evaluated();
47 assert(!p);
48 ASSERT_SAME_TYPE(InTemplate<std::is_constant_evaluated()>, InTemplate<true>);
49 static int local_static = std::is_constant_evaluated() ? 42 : -1;
50 assert(local_static == 42);
52 return 0;