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: unassig...@gcc.gnu.org

        ReportedBy: lucdan...@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.

Reply via email to