This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/54912] New: [C++11] Non-type argument to alias template is not a constant expression
- From: "lucdanton at free dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 12 Oct 2012 16:10:49 +0000
- Subject: [Bug c++/54912] New: [C++11] Non-type argument to alias template is not a constant expression
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54912
Bug #: 54912
Summary: [C++11] Non-type argument to alias template is not a
constant expression
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: lucdanton@free.fr
gcc version 4.8.0 20121008 (experimental) with flags
-Wall -pedantic -std=c++11
complains when fed the following program:
template<bool B>
using Bool = int;
template<typename T>
void foo()
{
using bar = Bool<(sizeof(T) >= 0)>; // line 7
}
int main()
{
foo<int>();
}
Compiler output:
main.cpp: In substitution of 'template<bool B> using Bool = int [with bool B =
(sizeof (T) >= 0)]':
main.cpp:7:38: required from here
main.cpp:7:38: error: integral expression '(sizeof (T) >= 0)' is not constant
using bar = Bool<(sizeof(T) >= 0)>;
^
main.cpp:7:38: error: trying to instantiate 'template<bool B> using Bool =
int'
Using the sizeof expression as the non-type parameter of a class template with
the same template parameter list as the alias template is accepted. That same
expression can also be used to initialize e.g. a constexpr bool variable, which
will in fact in turn be accepted as a parameter to Bool.
Previous snapshots of GCC used to accept this kind of code.