https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120942
Bug ID: 120942
Summary: internal compiler error happend when i lose include
some file
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: q1210081098 at gmail dot com
Target Milestone: ---
After running the following code, I received an internal compiler error. I know
this is due to the lack of # include<vector>, but it outputs an gcc error
```
#include <iostream>
#include <string>
#include <map>
#include <numeric>
int main() {
std::map<std::string, std::vector<int>> gradebook;
// Add students and their grades
gradebook["John"] = {85, 90, 77};
gradebook["Emily"] = {95, 88, 100};
gradebook["Michael"] = {88, 92, 100};
// Calculate the average grade for each student
for (const auto& student : gradebook) {
double average = std::accumulate(student.second.begin(),
student.second.end(), 0.0) / student.second.size();
std::cout << "Average grade for " << student.first << ": " << average
<< "\n";
}
return 0;
}
```
the output is
```
/GCC-15-COVERAGE/include/c++/15.0.1/format: In instantiation of ‘typename
std::basic_format_context<_Out, _CharT>::iterator
std::__format::__formatter_fp<_CharT>::format(_Fp,
std::basic_format_context<_Out, _CharT>&) const [with _Fp = _Float128; _Out =
std::__format::_Sink_iter<wchar_t>; _CharT = wchar_t; typename
std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<wchar_t>,
wchar_t>::iterator]’:
/GCC-15-COVERAGE/include/c++/15.0.1/format:2251:22: required from ‘typename
std::basic_format_context<_Out, _CharT>::iterator std::formatter<_Tp,
_CharT>::format(_Tp, std::basic_format_context<_Out, _CharT>&) const [with _Out
= std::__format::_Sink_iter<wchar_t>; _Tp = _Float128; _CharT = wchar_t;
typename std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<wchar_t>,
wchar_t>::iterator]’
2251 | { return _M_f.format(__u, __fc); }
| ~~~~~~~~~~~^~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:4166:41: required from
‘std::__format::_Formatting_scanner<std::__format::_Sink_iter<wchar_t>,
wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:38&)> [with auto:38 =
_Float128]’
4166 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:3650:44: required from
‘decltype(auto) std::basic_format_arg<_Context>::_M_visit(_Visitor&&,
std::__format::_Arg_t) [with _Visitor =
std::__format::_Formatting_scanner<std::__format::_Sink_iter<wchar_t>,
wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:38&)>; _Context =
std::basic_format_context<std::__format::_Sink_iter<wchar_t>, wchar_t>]’
3650 | return std::forward<_Visitor>(__vis)(_M_val._M_f128);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:3665:28: required from
‘decltype(auto) std::visit_format_arg(_Visitor&&, basic_format_arg<_Context>)
[with _Visitor = __format::_Formatting_scanner<__format::_Sink_iter<wchar_t>,
wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:38&)>; _Context =
basic_format_context<__format::_Sink_iter<wchar_t>, wchar_t>]’
3665 | return __arg._M_visit(std::forward<_Visitor>(__vis),
__arg._M_type);
|
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:4155:23: required from ‘constexpr
void std::__format::_Formatting_scanner<_Out,
_CharT>::_M_format_arg(std::size_t) [with _Out =
std::__format::_Sink_iter<wchar_t>; _CharT = wchar_t; std::size_t = long
unsigned int]’
4155 | std::visit_format_arg([this](auto& __arg) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
4156 | using _Type = remove_reference_t<decltype(__arg)>;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4157 | using _Formatter = typename _Context::template
formatter_type<_Type>;
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4158 | if constexpr (is_same_v<_Type, monostate>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4159 | __format::__invalid_arg_id_in_format_string();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4160 | else if constexpr (is_same_v<_Type, handle>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4161 | __arg.format(this->_M_pc, this->_M_fc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4162 | else if constexpr (is_default_constructible_v<_Formatter>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4163 | {
| ~
4164 | _Formatter __f;
| ~~~~~~~~~~~~~~~
4165 | this->_M_pc.advance_to(__f.parse(this->_M_pc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4166 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4167 | }
| ~
4168 | else
| ~~~~
4169 | static_assert(__format::__formattable_with<_Type,
_Context>);
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4170 | }, _M_fc.arg(__id));
| ~~~~~~~~~~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:4150:7: required from here
4150 | _M_format_arg(size_t __id) override
| ^~~~~~~~~~~~~
/GCC-15-COVERAGE/include/c++/15.0.1/format:1640:29: internal compiler error:
Segmentation fault
1640 | auto __to_chars = [&](char* __b, char* __e) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
1641 | if (__use_prec)
| ~~~~~~~~~~~~~~~
1642 | return __format::to_chars(__b, __e, __v, __fmt, __prec);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1643 | else if (__fmt != chars_format{})
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1644 | return __format::to_chars(__b, __e, __v, __fmt);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1645 | else
| ~~~~
1646 | return __format::to_chars(__b, __e, __v);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1647 | };
| ~
0x5d585b0 internal_error(char const*, ...)
.././../gcc-15/gcc/diagnostic-global-context.cc:517
0x273c6b6 crash_signal
.././../gcc-15/gcc/toplev.cc:322
g++: internal compiler error: Segmentation fault signal terminated program
cc1plus
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
See <https://gcc.gnu.org/bugs/> for instructions.
```