[LLVMbugs] [Bug 23402] New: Variable template instantiations in template arguments not considered constant expression
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Sun May 3 13:18:44 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=23402
Bug ID: 23402
Summary: Variable template instantiations in template arguments
not considered constant expression
Product: clang
Version: trunk
Hardware: PC
OS: FreeBSD
Status: NEW
Severity: normal
Priority: P
Component: C++14
Assignee: unassignedclangbugs at nondot.org
Reporter: daniel at octaforge.org
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
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
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150503/a92e6bd3/attachment.html>
More information about the llvm-bugs
mailing list