https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63925
Bug ID: 63925 Summary: ICE with C++14 constexpr when trying to constexprify std::min Product: gcc Version: 5.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ville.voutilainen at gmail dot com CC: jason at redhat dot com Test snippet: #include <initializer_list> struct _Iter_less_iter { template<typename _Iterator1, typename _Iterator2> constexpr bool operator()(_Iterator1 __it1, _Iterator2 __it2) const { return *__it1 < *__it2; } }; inline constexpr _Iter_less_iter __iter_less_iter() { return _Iter_less_iter(); } template<typename _ForwardIterator, typename _Compare> constexpr _ForwardIterator __min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) { if (__first == __last) return __first; _ForwardIterator __result = __first; while (++__first != __last) if (__comp(__first, __result)) __result = __first; return __result; } template<typename _ForwardIterator> constexpr _ForwardIterator inline min_element(_ForwardIterator __first, _ForwardIterator __last) { return __min_element(__first, __last, __iter_less_iter()); } template<typename _Tp> inline constexpr _Tp min(std::initializer_list<_Tp> __l) { return *min_element(__l.begin(), __l.end()); } int main() { constexpr int foo = min({6, 4}); } Trace: [ville@localhost ~]$ g++ --std=c++1y -o constexpr-test2 constexpr-test2.cpp constexpr-test2.cpp: In function ‘int main()’: constexpr-test2.cpp:44:26: in constexpr expansion of ‘min<int>(std::initializer_list<int>{((const int*)(& ._0)), 2u})’ constexpr-test2.cpp:40:22: in constexpr expansion of ‘min_element<const int*>(__l.std::initializer_list<_E>::begin<int>(), __l.std::initializer_list<_E>::end<int>())’ constexpr-test2.cpp:33:23: in constexpr expansion of ‘__min_element<const int*, _Iter_less_iter>(__first, __last, (__iter_less_iter(), _Iter_less_iter()))’ constexpr-test2.cpp:44:33: internal compiler error: in build2_stat, at tree.c:4283 constexpr int foo = min({6, 4}); ^ 0xf2b6b6 build2_stat(tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/tree.c:4283 0x9eeecf build2_stat_loc ../../gcc/tree.h:3560 0x9eeecf fold_build2_stat_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ../../gcc/fold-const.c:14233 0x7e6e77 cxx_eval_increment_expression ../../gcc/cp/constexpr.c:2569 0x7e6e77 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3195 0x7e9279 cxx_eval_binary_expression ../../gcc/cp/constexpr.c:1485 0x7e63dd cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3064 0x7e6917 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:2937 0x7e6b5b cxx_eval_conditional_expression ../../gcc/cp/constexpr.c:1511 0x7e6b5b cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3113 0x7eb105 cxx_eval_statement_list ../../gcc/cp/constexpr.c:2686 0x7e64fb cxx_eval_loop_expr ../../gcc/cp/constexpr.c:2714 0x7e64fb cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3248 0x7eb105 cxx_eval_statement_list ../../gcc/cp/constexpr.c:2686 0x7e5e7d cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3182 0x7e65a6 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:3188 0x7e513c cxx_eval_call_expression ../../gcc/cp/constexpr.c:1329 0x7e655d cxx_eval_constant_expression ../../gcc/cp/constexpr.c:2834 0x7e8b96 cxx_eval_store_expression ../../gcc/cp/constexpr.c:2527 0x7e6185 cxx_eval_constant_expression ../../gcc/cp/constexpr.c:2913 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <http://gcc.gnu.org/bugs.html> for instructions.