Using function argument as part of a constant expression - gcc vs clang : <p>Consider the following code snippet:</p>

<pre><code>template &lt;bool&gt; struct B { };

template &lt;typename T&gt;
constexpr bool pred(T t) { return true; } 

template &lt;typename T&gt;
auto f(T t) -&gt; decltype(B&lt;pred(t)&gt;{})
{
}
</code></pre>

<ul>
<li><p>clang++ <em>(trunk)</em> compiles the code</p></li>
<li><p>g++ <em>(trunk)</em> fails compilation with the following error:</p>

<pre><code>src:7:34: error: template argument 1 is invalid
auto f(T t) -&gt; decltype(B&lt;pred(t)&gt;{})
                                ^

src:7:34: error: template argument 1 is invalid
src:7:34: error: template argument 1 is invalid
src:7:34: error: template argument 1 is invalid
src:7:34: error: template argument 1 is invalid
src:7:34: error: template argument 1 is invalid
src:7:25: error: invalid template-id
auto f(T t) -&gt; decltype(B&lt;pred(t)&gt;{})
                        ^

src:7:36: error: class template argument deduction failed:
auto f(T t) -&gt; decltype(B&lt;pred(t)&gt;{})
                                    ^

src:7:36: error: no matching function for call to 'B()'
src:1:24: note: candidate: 'template&lt;bool &lt;anonymous&gt; &gt; B()-&gt; B&lt;&lt;anonymous&gt; &gt;'
template &lt;bool&gt; struct B { };
                        ^

src:1:24: note:   template argument deduction/substitution failed:
src:7:36: note:   couldn't deduce template parameter '&lt;anonymous&gt;'
auto f(T t) -&gt; decltype(B&lt;pred(t)&gt;{})
                                    ^
</code></pre>

<p><a href="https://godbolt.org/g/Xjjcwc" rel="noreferrer"><strong>live example on godbolt.org</strong></a></p></li>
</ul>

<hr>

<p>Even though g++'s diagnostic is misleading, I assume that the problem here is that <code>t</code> is not a <em>constant expression</em>. Changing the code to...</p>

<pre><code>decltype(B&lt;pred(T{})&gt;{})
</code></pre>

<p>...fixes the compilation error on g++: <a href="https://godbolt.org/g/F4vxAX" rel="noreferrer"><strong>live example on godbolt.org</strong></a></p>

<hr>

<p>What compiler is behaving correctly here? </p>
