https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117550
Bug ID: 117550 Summary: constexpr inlining and size optimizations Product: gcc Version: 14.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: alexey.lapshin at espressif dot com Target Milestone: --- When building applications for embedded systems with size optimizations (-Os) it appeared binary size boost when changed `-std=c++17` to `-std=c++2b`. Investigation shows that functions that use string methods from libstdc++ grew significantly because most of them have "constexpr" specifier that inlines methods implicitly. GCC is smart enough not to inline the method if two or more "constexpr" calls appear in the same translation unit. Otherwise, if only one call in the translation unit appears the function will be inlined. This could increase binary size significantly, depending on the project's structure. And it is unexpected behavior when "-Os" is applied. I did not find a solution how to suppress only "constexpr" functions inlining without affecting functions that are explicitly marked to be inlined. Could you please give me advice on how to achieve this? For now, I have a temporary solution to overcome this "-std=gnu++2b -Os -D_GLIBCXX20_CONSTEXPR=__attribute__((noinline)) -D__cpp_lib_constexpr_string= -D__cpp_lib_string_resize_and_overwrite="