Bug 63925 - ICE with C++14 constexpr when trying to constexprify std::min
Summary: ICE with C++14 constexpr when trying to constexprify std::min
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2014-11-18 05:04 UTC by Ville Voutilainen
Modified: 2014-11-18 20:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ville Voutilainen 2014-11-18 05:04:42 UTC
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.
Comment 1 Jason Merrill 2014-11-18 19:10:27 UTC
Author: jason
Date: Tue Nov 18 19:09:55 2014
New Revision: 217731

URL: https://gcc.gnu.org/viewcvs?rev=217731&root=gcc&view=rev
Log:
	PR c++/63925
	* constexpr.c (cxx_eval_increment_expression): Use POINTER_PLUS_EXPR.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-incr1.C
Comment 2 Jason Merrill 2014-11-18 20:08:03 UTC
Fixed.