Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?

Jonathan Wakely jwakely@redhat.com
Thu May 20 20:00:43 GMT 2021


On 20/05/21 19:50 +0000, unlvsur unlvsur wrote:
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
>                std::string_view str(*argv);
>                if(str.size()<4)
>                                __builtin_trap();
>                print(std::string_view(str.data()+4,str.size()));
>}
>
>g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>26kb (10kb of EH in libsupc++)
>
>#include<fast_io.h>
>
>int main(int argc,char** argv)
>{
>                std::string_view str(*argv);
>                print(str.substr(4));
>}
>
>g++ -o c c.cc -Ofast -std=c++20 -s -flto -march=native -I../fast_io/include -static-libstdc++
>87kb (10kb of EH in libsupc++)
>
>-fno-exceptions is useless here.
>
>I think the reason is because it introduces the translation unit of logic errors in libstdc++. That contains 60 kb of binary.

To really get rid of exceptions you need to build libstdc++ itself
with -fno-exceptions.





More information about the Libstdc++ mailing list