Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / utility / pairs / pairs.pair / ctor.not_constexpr_cxx11.verify.cpp
blobe994734fc408f7b32e2bb71fbc4abbe4f0346ceb
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 // REQUIRES: c++11
11 // <utility>
13 // Test that only the default constructor is constexpr in C++11
15 #include <utility>
16 #include <cassert>
18 struct ExplicitT {
19 constexpr explicit ExplicitT(int x) : value(x) {}
20 constexpr explicit ExplicitT(ExplicitT const& o) : value(o.value) {}
21 int value;
24 struct ImplicitT {
25 constexpr ImplicitT(int x) : value(x) {}
26 constexpr ImplicitT(ImplicitT const& o) : value(o.value) {}
27 int value;
30 void f() {
32 using P = std::pair<int, int>;
33 constexpr int x = 42;
34 constexpr P default_p{};
35 constexpr P copy_p(default_p);
36 constexpr P const_U_V(x, x); // expected-error {{must be initialized by a constant expression}}
37 constexpr P U_V(42, 101); // expected-error {{must be initialized by a constant expression}}
40 using P = std::pair<ExplicitT, ExplicitT>;
41 constexpr std::pair<int, int> other;
42 constexpr ExplicitT e(99);
43 constexpr P const_U_V(e, e); // expected-error {{must be initialized by a constant expression}}
44 constexpr P U_V(42, 101); // expected-error {{must be initialized by a constant expression}}
45 constexpr P pair_U_V(other); // expected-error {{must be initialized by a constant expression}}
48 using P = std::pair<ImplicitT, ImplicitT>;
49 constexpr std::pair<int, int> other;
50 constexpr ImplicitT i = 99;
51 constexpr P const_U_V = {i, i}; // expected-error {{must be initialized by a constant expression}}
52 constexpr P U_V = {42, 101}; // expected-error {{must be initialized by a constant expression}}
53 constexpr P pair_U_V = other; // expected-error {{must be initialized by a constant expression}}