| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// REQUIRES: c++11 |
| 10 |
|
| 11 |
// <utility> |
| 12 |
|
| 13 |
// Test that only the default constructor is constexpr in C++11 |
| 14 |
|
| 15 |
#include <utility> |
| 16 |
#include <cassert> |
| 17 |
|
| 18 |
struct ExplicitT { |
| 19 |
constexpr explicit ExplicitT(int x) : value(x) {} |
| 20 |
constexpr explicit ExplicitT(ExplicitT const& o) : value(o.value) {} |
| 21 |
int value; |
| 22 |
}; |
| 23 |
|
| 24 |
struct ImplicitT { |
| 25 |
constexpr ImplicitT(int x) : value(x) {} |
| 26 |
constexpr ImplicitT(ImplicitT const& o) : value(o.value) {} |
| 27 |
int value; |
| 28 |
}; |
| 29 |
|
| 30 |
void f() { |
| 31 |
{ |
| 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}} |
| 38 |
} |
| 39 |
{ |
| 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}} |
| 46 |
} |
| 47 |
{ |
| 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}} |
| 54 |
} |
| 55 |
} |