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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Another variation:

template<typename _Tp>
struct vector
{
      struct _Temp_value
      {
          constexpr
          _Temp_value()
          {
          }

#ifndef ICE
        constexpr
        ~_Temp_value()
        { }
#endif

        union _Storage
        {
          constexpr _Storage() : _M_byte() { }
          ~_Storage() { }
          unsigned char _M_byte;
        };

        _Storage _M_storage;
      };

    constexpr void
    insert()
    {
      _Temp_value v;
    }
};

constexpr bool
test()
{
  vector<int> v;
  v.insert();

  return true;
}

static_assert( test() );


With -std=c++20 this prints:

ce.C:43:20: error: non-constant condition for static assertion
   43 | static_assert( test() );
      |                ~~~~^~
ce.C:43:20:   in 'constexpr' expansion of 'test()'
ce.C:38:11: error: 'constexpr void vector<_Tp>::insert() [with _Tp = int]'
called in a constant expression
   38 |   v.insert();
      |   ~~~~~~~~^~
ce.C:28:5: note: 'constexpr void vector<_Tp>::insert() [with _Tp = int]' is not
usable as a 'constexpr' function because:
   28 |     insert()
      |     ^~~~~~


But with -std=c++20 -DICE it ICEs:

ce.C:43:20: error: non-constant condition for static assertion
   43 | static_assert( test() );
      |                ~~~~^~
ce.C:43:20:   in ‘constexpr’ expansion of ‘test()’
ce.C:38:11: error: ‘constexpr void vector<_Tp>::insert() [with _Tp = int]’
called in a constant expression
   38 |   v.insert();
      |   ~~~~~~~~^~
ce.C:28:5: note: ‘constexpr void vector<_Tp>::insert() [with _Tp = int]’ is not
usable as a ‘constexpr’ function because:
   28 |     insert()
      |     ^~~~~~
ce.C:31:5: error: call to non-‘constexpr’ function
‘vector<int>::_Temp_value::~_Temp_value()’
   31 |     }
      |     ^
ce.C:4:14: note: ‘vector<int>::_Temp_value::~_Temp_value()’ is not usable as a
‘constexpr’ function because:
    4 |       struct _Temp_value
      |              ^~~~~~~~~~~
ce.C:4:14: internal compiler error: in synthesized_method_walk, at
cp/method.c:2531
0x6b9809 synthesized_method_walk
        /home/jwakely/src/gcc/gcc/gcc/cp/method.c:2531
0xa3f243 explain_implicit_non_constexpr(tree_node*)
        /home/jwakely/src/gcc/gcc/gcc/cp/method.c:2887
0x977a17 explain_invalid_constexpr_fn(tree_node*)
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:976
0x9767f7 potential_constant_expression_1
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:8220
0x9758a1 potential_constant_expression_1
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:8445
0x976d38 potential_constant_expression_1(tree_node*, bool, bool, bool, int)
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:9126
0x976d38 require_potential_rvalue_constant_expression(tree_node*)
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:9160
0x977638 explain_invalid_constexpr_fn(tree_node*)
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:984
0x96d8aa cxx_eval_call_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:2629
0x96f406 cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6344
0x96f362 cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6674
0x96f1c8 cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6542
0x97054a cxx_eval_statement_list
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:5881
0x97054a cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7013
0x96f3e8 cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7048
0x96cae0 cxx_eval_call_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:2789
0x96f406 cxx_eval_constant_expression
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:6344
0x973296 cxx_eval_outermost_constant_expr
        /home/jwakely/src/gcc/gcc/gcc/cp/constexpr.c:7409
0xb5bb39 finish_static_assert(tree_node*, tree_node*, unsigned int, bool, bool)
        /home/jwakely/src/gcc/gcc/gcc/cp/semantics.c:10457
0xaa1b5d cp_parser_static_assert
        /home/jwakely/src/gcc/gcc/gcc/cp/parser.c:16166
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.

Reply via email to