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

            Bug ID: 84098
           Summary: [8 Regression] ICE when using a lambda in a in-class
                    static member initialization
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: benni.buch at gmail dot com
  Target Milestone: ---

struct A{};

template < typename >
struct Test{
    static constexpr auto var = []{};
};

int main(){
    (void)Test< A >::var;
}


$ g++ -std=c++11 main.cpp 
main.cpp: In instantiation of 'struct Test<A>':
main.cpp:9:20:   required from here
main.cpp:5:34: internal compiler error: in lookup_template_class_1, at
cp/pt.c:8957
     static constexpr auto var = []{};
                                  ^
0x612d1c lookup_template_class_1
        ../../gcc/gcc/cp/pt.c:8957
0x612d1c lookup_template_class(tree_node*, tree_node*, tree_node*, tree_node*,
int, int)
        ../../gcc/gcc/cp/pt.c:9167
0x94017a tsubst_aggr_type
        ../../gcc/gcc/cp/pt.c:12035
0x93a69e tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.c:13668
0x9412b2 tsubst_decl
        ../../gcc/gcc/cp/pt.c:12965
0x93a7af tsubst(tree_node*, tree_node*, int, tree_node*)
        ../../gcc/gcc/cp/pt.c:13586
0x958cea instantiate_class_template_1
        ../../gcc/gcc/cp/pt.c:10635
0x958cea instantiate_class_template(tree_node*)
        ../../gcc/gcc/cp/pt.c:10920
0x999afd complete_type(tree_node*)
        ../../gcc/gcc/cp/typeck.c:136
0x8f833a cp_parser_nested_name_specifier_opt
        ../../gcc/gcc/cp/parser.c:6441
0x8f9e45 cp_parser_simple_type_specifier
        ../../gcc/gcc/cp/parser.c:17111
0x8faf57 cp_parser_postfix_expression
        ../../gcc/gcc/cp/parser.c:6945
0x8fbbc0 cp_parser_unary_expression
        ../../gcc/gcc/cp/parser.c:8281
0x8dc73f cp_parser_cast_expression
        ../../gcc/gcc/cp/parser.c:9049
0x8dc901 cp_parser_cast_expression
        ../../gcc/gcc/cp/parser.c:9001
0x8dcf4a cp_parser_binary_expression
        ../../gcc/gcc/cp/parser.c:9150
0x8de714 cp_parser_assignment_expression
        ../../gcc/gcc/cp/parser.c:9437
0x8dee28 cp_parser_expression
        ../../gcc/gcc/cp/parser.c:9606
0x8e0ad8 cp_parser_expression_statement
        ../../gcc/gcc/cp/parser.c:11075
0x8e683d cp_parser_statement
        ../../gcc/gcc/cp/parser.c:10879
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

$ g++ --version
g++ (GCC) 8.0.1 20180129 (experimental)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Known to work with g++-5 and g++6, both give an error message but don't run
into an ICE, clang accepts the code.

$ g++-6 -std=c++11 main.cpp 
main.cpp:5:27: error: 'constexpr const Test<A>::<lambda()> Test<A>::var',
declared using local type 'const Test<A>::<lambda()>', is used but never
defined [-fpermissive]
     static constexpr auto var = []{};
                           ^~~

$ g++-6 --version
g++-6 (Ubuntu/Linaro 6.3.0-18ubuntu2~16.04) 6.3.0 20170519
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++-5 --version
g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Reply via email to