https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118891
Bug ID: 118891
Summary: gcc 14 fails to build from source on aarch64_be:
"error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’"
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: bootstrap
Assignee: unassigned at gcc dot gnu.org
Reporter: marcus at mc dot pp.se
Target Milestone: ---
When building gcc 14 (I tried 14.2 and 14.3; 13.3 is not affected) natively on
aarch64_be-linux-gnu, the compilation fails during stage2 when compiling
stacktrace.cc from libstdc++-v3/src/c++23. The compilation error is
"error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’", which makes no sense
since no-rtti is neither on the command line nor in gcc/specs. And in
fact, if I _do_ add -fno-rtti to the command line, then the compilation
succeeds...
I have minimized the reproducation this far:
---8<---
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build # cat gotcha.cc
#include <format>
[[gnu::optimize("no-optimize-sibling-calls")]]
void fnord()
{
}
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build # ./gcc/xgcc
-B./gcc -nostdinc++ -I../gcc-14.3.9999/libstdc++-v3/../libgcc
-Iaarch64_be-unknown-linux-gnu/libstdc++-v3/include/aarch64_be-unknown-linux-gnu
-Iaarch64_be-unknown-linux-gnu/libstdc++-v3/include
-I../gcc-14.3.9999/libstdc++-v3/libsupc++ -std=gnu++23 -c gotcha.cc -o gotcha.o
In file included from
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.h:888,
from
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/locale:41,
from
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:47,
from gotcha.cc:1:
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc: In
instantiation of ‘const _Facet* std::__try_use_facet(const locale&) [with
_Facet = __cxx11::numpunct<wchar_t>]’:
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc:205:59:
required from ‘const _Facet& std::use_facet(const locale&) [with _Facet =
__cxx11::numpunct<wchar_t>]’
205 | if (const _Facet* __f = std::__try_use_facet<_Facet>(__loc))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:1170:53: required
from ‘typename std::basic_format_context<_Out, _CharT>::iterator
std::__format::__formatter_int<_CharT>::format(bool,
std::basic_format_context<_Out, _CharT>&) const [with _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]’
1170 | auto& __np =
std::use_facet<numpunct<_CharT>>(__fc.locale());
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:2148: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 = bool;
_CharT = wchar_t; typename std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<wchar_t>,
wchar_t>::iterator]’
2148 | { return _M_f.format(__u, __fc); }
| ~~~~~~~~~~~^~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4055:41: required
from ‘std::__format::_Formatting_scanner<std::__format::_Sink_iter<wchar_t>,
wchar_t>::_M_format_arg(std::size_t)::<lambda(auto:36&)> [with auto:36 = bool]’
4055 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:3510: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:36&)>; _Context =
std::basic_format_context<std::__format::_Sink_iter<wchar_t>, wchar_t>]’
3510 | return std::forward<_Visitor>(__vis)(_M_val._M_bool);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:3570: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:36&)>; _Context =
basic_format_context<__format::_Sink_iter<wchar_t>, wchar_t>]’
3570 | return __arg._M_visit(std::forward<_Visitor>(__vis),
__arg._M_type);
|
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4044: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]’
4044 | std::visit_format_arg([this](auto& __arg) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
4045 | using _Type = remove_reference_t<decltype(__arg)>;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4046 | using _Formatter = typename _Context::template
formatter_type<_Type>;
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4047 | if constexpr (is_same_v<_Type, monostate>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4048 | __format::__invalid_arg_id_in_format_string();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4049 | else if constexpr (is_same_v<_Type, handle>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4050 | __arg.format(this->_M_pc, this->_M_fc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4051 | else if constexpr (is_default_constructible_v<_Formatter>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4052 | {
| ~
4053 | _Formatter __f;
| ~~~~~~~~~~~~~~~
4054 | this->_M_pc.advance_to(__f.parse(this->_M_pc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4055 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4056 | }
| ~
4057 | else
| ~~~~
4058 | static_assert(__format::__formattable_with<_Type,
_Context>);
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4059 | }, _M_fc.arg(__id));
| ~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4039:7: required
from here
4039 | _M_format_arg(size_t __id) override
| ^~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc:145:14:
error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’
145 | return dynamic_cast<const _Facet*>(__facets[__i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc: In
instantiation of ‘const _Facet* std::__try_use_facet(const locale&) [with
_Facet = __cxx11::numpunct<char>]’:
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc:205:59:
required from ‘const _Facet& std::use_facet(const locale&) [with _Facet =
__cxx11::numpunct<char>]’
205 | if (const _Facet* __f = std::__try_use_facet<_Facet>(__loc))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:1170:53: required
from ‘typename std::basic_format_context<_Out, _CharT>::iterator
std::__format::__formatter_int<_CharT>::format(bool,
std::basic_format_context<_Out, _CharT>&) const [with _Out =
std::__format::_Sink_iter<char>; _CharT = char; typename
std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<char>, char>::iterator]’
1170 | auto& __np =
std::use_facet<numpunct<_CharT>>(__fc.locale());
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:2148: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<char>; _Tp = bool;
_CharT = char; typename std::basic_format_context<_Out, _CharT>::iterator =
std::basic_format_context<std::__format::_Sink_iter<char>, char>::iterator]’
2148 | { return _M_f.format(__u, __fc); }
| ~~~~~~~~~~~^~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4055:41: required
from ‘std::__format::_Formatting_scanner<std::__format::_Sink_iter<char>,
char>::_M_format_arg(std::size_t)::<lambda(auto:36&)> [with auto:36 = bool]’
4055 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:3510: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<char>,
char>::_M_format_arg(std::size_t)::<lambda(auto:36&)>; _Context =
std::basic_format_context<std::__format::_Sink_iter<char>, char>]’
3510 | return std::forward<_Visitor>(__vis)(_M_val._M_bool);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:3570:28: required
from ‘decltype(auto) std::visit_format_arg(_Visitor&&,
basic_format_arg<_Context>)[with _Visitor =
__format::_Formatting_scanner<__format::_Sink_iter<char>,
char>::_M_format_arg(std::size_t)::<lambda(auto:36&)>; _Context =
basic_format_context<__format::_Sink_iter<char>, char>]’
3570 | return __arg._M_visit(std::forward<_Visitor>(__vis),
__arg._M_type);
|
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4044:23: required
from ‘constexpr void std::__format::_Formatting_scanner<_Out,
_CharT>::_M_format_arg(std::size_t) [with _Out =
std::__format::_Sink_iter<char>; _CharT = char; std::size_t = long unsigned
int]’
4044 | std::visit_format_arg([this](auto& __arg) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
4045 | using _Type = remove_reference_t<decltype(__arg)>;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4046 | using _Formatter = typename _Context::template
formatter_type<_Type>;
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4047 | if constexpr (is_same_v<_Type, monostate>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4048 | __format::__invalid_arg_id_in_format_string();
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4049 | else if constexpr (is_same_v<_Type, handle>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4050 | __arg.format(this->_M_pc, this->_M_fc);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4051 | else if constexpr (is_default_constructible_v<_Formatter>)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4052 | {
| ~
4053 | _Formatter __f;
| ~~~~~~~~~~~~~~~
4054 | this->_M_pc.advance_to(__f.parse(this->_M_pc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4055 | this->_M_fc.advance_to(__f.format(__arg, this->_M_fc));
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4056 | }
| ~
4057 | else
| ~~~~
4058 | static_assert(__format::__formattable_with<_Type,
_Context>);
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4059 | }, _M_fc.arg(__id));
| ~~~~~~~~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/format:4039:7: required
from here
4039 | _M_format_arg(size_t __id) override
| ^~~~~~~~~~~~~
aarch64_be-unknown-linux-gnu/libstdc++-v3/include/bits/locale_classes.tcc:145:14:
error: ‘dynamic_cast’ not permitted with ‘-fno-rtti’
145 | return dynamic_cast<const _Facet*>(__facets[__i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build #
---8<---
The error message is exactly the same as when compiling stacktrace.cc.
(I can provide complete build logs if desired.) Of note is that if I comment
out the gnu::optimize attribute, then the compilation succeeds:
---8<---
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build # cat gotcha2.cc
#include <format>
// [[gnu::optimize("no-optimize-sibling-calls")]]
void fnord()
{
}
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build # ./gcc/xgcc
-B./gcc -nostdinc++ -I../gcc-14.3.9999/libstdc++-v3/../libgcc
-Iaarch64_be-unknown-linux-gnu/libstdc++-v3/include/aarch64_be-unknown-linux-gnu
-Iaarch64_be-unknown-linux-gnu/libstdc++-v3/include
-I../gcc-14.3.9999/libstdc++-v3/libsupc++ -std=gnu++23 -c gotcha2.cc -o
gotcha2.o
momoka_be /var/tmp/portage/sys-devel/gcc-14.3.9999/work/build #
---8<---
Could the attribute cause some corruption of internal compiler state perhaps?