https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72507

            Bug ID: 72507
           Summary: incorrectly accepts invalid C++11 code that tries to
                    allocate an incomplete type
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

It seems to affect all versions since 4.7.x. 


$ g++-trunk -v
Using built-in specs.
COLLECT_GCC=g++-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160725 (experimental) [trunk revision 238706] (GCC) 
$ 
$ g++-trunk -c -Wall -Wextra -std=c++11 -pedantic test.cpp
$ 
$ clang++-3.8 -c -std=c++11 test.cpp
test.cpp:3:60: error: allocation of incomplete type 'A<int>'
  static const int t = ([] (A < T > *) { return 0; }) (new A < T >);
                                                           ^~~~~~~
test.cpp:6:11: note: in instantiation of template class 'A<int>' requested here
A < int > a;
          ^
test.cpp:1:32: note: definition of 'A<int>' is not complete until the closing
'}'
template < typename T > struct A
                               ^
test.cpp:3:25: error: a lambda expression may not appear inside of a constant
expression
  static const int t = ([] (A < T > *) { return 0; }) (new A < T >);
                        ^
2 errors generated.
$ 


----------------------------------------------------------------------


template < typename T > struct A
{
  static const int t = ([] (A < T > *) { return 0; }) (new A < T >);
};

A < int > a;

Reply via email to