public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54912] New: [C++11] Non-type argument to alias template is not a constant expression
@ 2012-10-12 16:11 lucdanton at free dot fr
  2012-10-12 16:55 ` [Bug c++/54912] [4.8 Regression] " paolo.carlini at oracle dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: lucdanton at free dot fr @ 2012-10-12 16:11 UTC (permalink / raw)
  To: gcc-bugs


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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-21 22:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-12 16:11 [Bug c++/54912] New: [C++11] Non-type argument to alias template is not a constant expression lucdanton at free dot fr
2012-10-12 16:55 ` [Bug c++/54912] [4.8 Regression] " paolo.carlini at oracle dot com
2012-10-12 17:08 ` paolo.carlini at oracle dot com
2012-10-21 22:52 ` paolo.carlini at oracle dot com
2012-10-21 22:53 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).