Home | History | Annotate | Download | only in pairs.pair
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // REQUIRES: c++11
     11 
     12 // <utility>
     13 
     14 // Test that only the default constructor is constexpr in C++11
     15 
     16 #include <utility>
     17 #include <cassert>
     18 
     19 struct ExplicitT {
     20   constexpr explicit ExplicitT(int x) : value(x) {}
     21   constexpr explicit ExplicitT(ExplicitT const& o) : value(o.value) {}
     22   int value;
     23 };
     24 
     25 struct ImplicitT {
     26   constexpr ImplicitT(int x) : value(x) {}
     27   constexpr ImplicitT(ImplicitT const& o) : value(o.value) {}
     28   int value;
     29 };
     30 
     31 int main()
     32 {
     33     {
     34         using P = std::pair<int, int>;
     35         constexpr int x = 42;
     36         constexpr P default_p{};
     37         constexpr P copy_p(default_p);
     38         constexpr P const_U_V(x, x); // expected-error {{must be initialized by a constant expression}}
     39         constexpr P U_V(42, 101); // expected-error {{must be initialized by a constant expression}}
     40     }
     41     {
     42         using P = std::pair<ExplicitT, ExplicitT>;
     43         constexpr std::pair<int, int> other;
     44         constexpr ExplicitT e(99);
     45         constexpr P const_U_V(e, e); // expected-error {{must be initialized by a constant expression}}
     46         constexpr P U_V(42, 101); // expected-error {{must be initialized by a constant expression}}
     47         constexpr P pair_U_V(other); // expected-error {{must be initialized by a constant expression}}
     48     }
     49     {
     50         using P = std::pair<ImplicitT, ImplicitT>;
     51         constexpr std::pair<int, int> other;
     52         constexpr ImplicitT i = 99;
     53         constexpr P const_U_V = {i, i}; // expected-error {{must be initialized by a constant expression}}
     54         constexpr P U_V = {42, 101}; // expected-error {{must be initialized by a constant expression}}
     55         constexpr P pair_U_V = other; // expected-error {{must be initialized by a constant expression}}
     56     }
     57 }
     58