<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Feb 18, 2014 at 12:03 PM, Marshall Clow <span dir="ltr"><<a href="mailto:mclow.lists@gmail.com" target="_blank">mclow.lists@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Consider the following code:<br>
<br>
        constexpr int x = 0;<br>
        constexpr int y = 1;<br>
        constexpr std::pair<const int &, const int &> p {x,y};<br>
<br>
Shouldn’t that compile? (with -std=c++1y)<br></blockquote><div><br></div><div>Depends. If this is namespace-scope, then yes. If it's block-scope, then no (it should compile only if the addresses of x and y are constant).</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In C++14,  we have:<br>
         constexpr pair(const T1& x, const T2& y);<br>
(and yes, libc++ implements it that way).<br>
<br>
But clang rejects it, with:<br>
junk2.cpp:18:46: error: constexpr variable 'p' must be initialized by a constant<br>
      expression<br>
        constexpr std::pair<const int&, const int&> p { x, y };<br>
                                                    ^~~~~~~~<br>
junk2.cpp:18:46: note: reference to 'x' is not a constant expression<br>
junk2.cpp:15:16: note: declared here<br>
        constexpr int x = 0;<br>
<br>
with the caret pointing at the ‘p’ in "> p { x, y };”<br>
<br>
<br>
Followup question. Assuming that this should compile, then what about this?<br>
<br>
        typedef std::pair<const int &, const int &> p_t;<br>
        constexpr int x = 0;<br>
        constexpr int y = 1;<br>
        constexpr p_t foo () { return p_t{x,y}; }<br>
<br>
        constexpr p_t bar = foo();<br>
<br>
pair’s copy and copy constructors are defined as “= default”.<br>
<br>
But, 20.3.2/2 says:<br>
<br>
The defaulted move and copy constructor, respectively, of pair shall be a constexpr function if and only if all required element-wise initializations for copy and move, respectively, would satisfy the requirements for a constexpr function.</blockquote>
<div><br></div><div>I think this should work (and indeed it seems to with libc++, but not with libstdc++ where the pair move constructor is not constexpr).</div></div></div></div>