https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93921
Bug ID: 93921 Summary: -Os generates much bigger code than -O{1,2,3,fast} for std::string::size Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bsnoksru at cisco dot com Target Milestone: --- Testing with the following code-fragment #include <string> #include <string_view> int foo() { using namespace std::literals; return "asdf"s.size(); } int bar() { using namespace std::string_view_literals; return "asdf"sv.size(); } using g++ from `trunk` (as reported by godbolt), with flags "--std=c++17" and different optimiziation levels show that the string-view size gets inlined to a constant for all relevant optimization levels, while the string-size code gets inflated when optimizing for size.