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

            Bug ID: 121715
           Summary: ICE with std::string = nullptr inside lambda within
                    decltype under C++23 mode
           Product: gcc
           Version: 14.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jirehguo at tju dot edu.cn
  Target Milestone: ---

The following C++ code causes an Internal Compiler Error (ICE) when compiled
with -std=c++23 using GCC versions from 12.1 up to 14.3.0. However, no ICE with
-std=c++20 using same version gcc.
Notably, this ICE does not occur on the latest trunk version of GCC.

Reproducer link: https://godbolt.org/z/r93Y5M6TG

Code:
-------------
#include <string>
#include <vector>

template <class T>
void spam(decltype([] {
  const int size = 10;
  std::vector<std::string> array(size, "non-null");
  try {
    array[5] = nullptr;
  } catch (const std::exception &e) {
  }
}) (*s)[sizeof(T)]) {}

int main() {
  spam<char>(nullptr);
}


Command:
-------------
g++ test.cpp -std=c++23


Output:
-------------
<source>: In substitution of 'template<class T> void spam(decltype (<lambda>)
(*)[sizeof (T)]) [with T = char]':
<source>:15:13:   required from here
   15 |   spam<char>(nullptr);
      |   ~~~~~~~~~~^~~~~~~~~
<source>:9:16: error: use of deleted function
'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::nullptr_t)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>; std::nullptr_t = std::nullptr_t]'
    9 |     array[5] = nullptr;
      |                ^~~~~~~
In file included from
/cefs/57/575cc65f13a9ae435d7c97e7_converted_gcc-14.3.0/include/c++/14.3.0/string:54,
                 from <source>:1:
/cefs/57/575cc65f13a9ae435d7c97e7_converted_gcc-14.3.0/include/c++/14.3.0/bits/basic_string.h:749:21:
note: declared here
  749 |       basic_string& operator=(nullptr_t) = delete;
      |                     ^~~~~~~~
<source>:9:16: note: use '-fdiagnostics-all-candidates' to display considered
candidates
    9 |     array[5] = nullptr;
      |                ^~~~~~~
<source>:9:16: error: use of deleted function
'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&
std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator=(std::nullptr_t)
[with _CharT = char; _Traits = std::char_traits<char>; _Alloc =
std::allocator<char>; std::nullptr_t = std::nullptr_t]'
/cefs/57/575cc65f13a9ae435d7c97e7_converted_gcc-14.3.0/include/c++/14.3.0/bits/basic_string.h:749:21:
note: declared here
  749 |       basic_string& operator=(nullptr_t) = delete;
      |                     ^~~~~~~~
<source>:9:16: note: use '-fdiagnostics-all-candidates' to display considered
candidates
    9 |     array[5] = nullptr;
      |                ^~~~~~~
'
internal compiler error: error reporting routines re-entered.
0x202f985 diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x203084d error(char const*, ...)
        ???:0
0x9637fc process_outer_var_ref(tree_node*, int, bool)
        ???:0
0x947636 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x93d5e0 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x2042cde pp_format(pretty_printer*, text_info*, urlifier const*)
        ???:0
0x2044225 pp_verbatim(pretty_printer*, char const*, ...)
        ???:0
0x202f5bd diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x203084d error(char const*, ...)
        ???:0
0x833cf8 mark_used(tree_node*, int)
        ???:0
0x7a4540 build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
        ???:0
0x9a2ac5 cp_build_modify_expr(unsigned int, tree_node*, tree_code, tree_node*,
int)
        ???:0
0x9a3254 build_x_modify_expr(unsigned int, tree_node*, tree_code, tree_node*,
tree_node*, int)
        ???:0
0x947636 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x93d5e0 tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x93d10d tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x93d10d tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x935def instantiate_decl(tree_node*, bool, bool)
        ???:0
0x94ff93 instantiate_pending_templates(int)
        ???:0
0x8361b8 c_parse_final_cleanups()
        ???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Reply via email to