<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Variable template instantiations in template arguments not considered constant expression"
href="https://llvm.org/bugs/show_bug.cgi?id=23402">23402</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Variable template instantiations in template arguments not considered constant expression
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>FreeBSD
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>daniel@octaforge.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Hello,
I found a bug recently (I believe). This code does not compile with Clang (3.4
as well as 3.7-svn, on FreeBSD x64):
-----
#include <stdio.h>
template<typename T> struct foo {
static constexpr bool value = false;
};
template<> struct foo<int> {
static constexpr bool value = true;
};
template<typename T> static constexpr bool Foo = foo<T>::value;
template<typename T, bool B = Foo<T>> struct bar {};
int main() {
bar<int> x;
return 0;
}
-----
The error is:
const.cpp:13:31: error: non-type template argument is not a constant expression
template<typename T, bool B = Foo<T>> struct bar {};
g++ 5.1 does not exhibit this behavior.
keep in mind that changing to (that is, turning the variable template into
non-template constexpr variable):
-----
static constexpr bool Foo = foo<int>::value;
template<typename T, bool B = Foo> struct bar {};
-----
works in both g++ and clang.
Adding a wrapper also works in both g++ and clang:
-----
template<typename T> static constexpr bool Foo = foo<T>::value;
template<typename T> struct wrap {
static constexpr bool value = Foo<T>;
};
template<typename T, bool B = wrap<T>::value> struct bar {};
-----
and a static assertion also works in both gcc and clang (does not cause the
error):
-----
template<typename T> static constexpr bool Foo = foo<T>::value;
int main() {
static_assert(Foo<int>, "hello");
return 0;
}
-----
So it only happens when the "Foo<T>" happens as a default value for a non-type
template argument. That made me think this is a Clang bug.
I compile with "-std=c++14 -Wall -Wextra".
Please let me know if you need any further information.
Regards,
Daniel</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>