https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68206
Bug ID: 68206 Summary: ICE: unimplemented: unexpected AST of kind loop_expr in potential_constant_expression_1 Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: chrisb2244 at gmail dot com Target Milestone: --- Code below hits ICE. /////////////////////////////////////////////// #include <array> #include <iostream> template<typename T, uint N> class A { using Arr = std::array<T,N>; public: constexpr A() = default; constexpr void displayArr() { for (uint n=0; n<N; n++) { std::cout << arr_[n]; } } private: static constexpr Arr makeArr() { Arr temp{}; for (uint n=0; n<N; n++) { temp[n] = T(n); } return temp; } static constexpr Arr arr_ = makeArr(); }; int main() { A<double, 5> a; a.displayArr(); // If this isn't called - no problems return 0; } /////////////////////////////////////////////// Error: loopFail.cpp: In instantiation of 'constexpr const Arr A<double, 5u>::arr_': loopFail.cpp:13:30: required from 'constexpr void A<T, N>::displayArr() const [with T = double; unsigned int N = 5u]' loopFail.cpp:31:18: required from here loopFail.cpp:26:40: error: 'static constexpr A<T, N>::Arr A<T, N>::makeArr() [with T = double; unsigned int N = 5u; A<T, N>::Arr = std::array<double, 5ul>]' called in a constant expression static constexpr Arr arr_ = makeArr(); ^ loopFail.cpp:18:26: note: 'static constexpr A<T, N>::Arr A<T, N>::makeArr() [with T = double; unsigned int N = 5u; A<T, N>::Arr = std::array<double, 5ul>]' is not usable as a constexpr function because: static constexpr Arr makeArr() { ^ loopFail.cpp:18:26: sorry, unimplemented: unexpected AST of kind loop_expr loopFail.cpp:18:26: internal compiler error: in potential_constant_expression_1, at cp/constexpr.c:4639 0x8064db potential_constant_expression_1 ../../gcc-svn-sources/gcc/cp/constexpr.c:4639 0x805d0d potential_constant_expression_1 ../../gcc-svn-sources/gcc/cp/constexpr.c:4257 0x805d0d potential_constant_expression_1 ../../gcc-svn-sources/gcc/cp/constexpr.c:4257 0x805d0d potential_constant_expression_1 ../../gcc-svn-sources/gcc/cp/constexpr.c:4257 0x7fd453 require_potential_rvalue_constant_expression(tree_node*) ../../gcc-svn-sources/gcc/cp/constexpr.c:4680 0x7fd453 explain_invalid_constexpr_fn(tree_node*) ../../gcc-svn-sources/gcc/cp/constexpr.c:842 0x7fdbc1 cxx_eval_call_expression ../../gcc-svn-sources/gcc/cp/constexpr.c:1258 0x7ffa11 cxx_eval_constant_expression ../../gcc-svn-sources/gcc/cp/constexpr.c:3207 0x805211 cxx_eval_outermost_constant_expr ../../gcc-svn-sources/gcc/cp/constexpr.c:3746 0x686fbe store_init_value(tree_node*, tree_node*, vec<tree_node*, va_gc, vl_embed>**, int) ../../gcc-svn-sources/gcc/cp/typeck2.c:823 0x5ed78f check_initializer ../../gcc-svn-sources/gcc/cp/decl.c:6111 0x60cdb4 cp_finish_decl(tree_node*, tree_node*, bool, tree_node*, int) ../../gcc-svn-sources/gcc/cp/decl.c:6739 0x642270 instantiate_decl(tree_node*, int, bool) ../../gcc-svn-sources/gcc/cp/pt.c:21459 0x6c0a22 mark_used(tree_node*, int) ../../gcc-svn-sources/gcc/cp/decl2.c:5152 0x64d7bb tsubst_copy ../../gcc-svn-sources/gcc/cp/pt.c:13889 0x659ce2 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-svn-sources/gcc/cp/pt.c:16692 0x65b6e8 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-svn-sources/gcc/cp/pt.c:15910 0x65a1b7 tsubst_copy_and_build(tree_node*, tree_node*, int, tree_node*, bool, bool) ../../gcc-svn-sources/gcc/cp/pt.c:15879 0x6462e0 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-svn-sources/gcc/cp/pt.c:15498 0x644a26 tsubst_expr(tree_node*, tree_node*, int, tree_node*, bool) ../../gcc-svn-sources/gcc/cp/pt.c:14875 I'm not certain the code is valid, but even in the case it isn't - shouldn't I just be told what is wrong with it? In particular, the error line: makeArr() [ with T = ... ] is not usable as a constexpr function because: static constexpr Arr makeArr() { ^ doesn't tell me much.