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 19:35:06 GMT 2021
On 20/05/21 19:27 +0000, unlvsur unlvsur wrote:
>Well. It comes from snprintf. You cannot use any stdio functionalities.
>
>For example
>https://github.com/gcc-mirror/gcc/blob/4f4a2f199baf46d35492edadc16f30f32920c4df/libstdc%2B%2B-v3/include/bits/stl_vector.h#L1070
But that doesn't use snprintf.
>
>https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/include/experimental/string_view#L274
And that doesn't use snprintf either.
Have you actually seen a dependency on stdio from these functions, or
are you just assuming?
>We need something which is a silent EH thrown, this format string thrown stuff will always introduce dependencies silently.
>
>This also hurts optimizations
>
>[cid:image002.png@01D74D8C.9AD99570]
>
>
>Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows 10
>
>From: Jonathan Wakely<mailto:jwakely@redhat.com>
>Sent: Thursday, May 20, 2021 15:21
>To: Jonathan Wakely<mailto:jwakely.gcc@gmail.com>
>Cc: unlvsur unlvsur<mailto:unlvsur@live.com>; unlvsur unlvsur via Libstdc++<mailto:libstdc++@gcc.gnu.org>
>Subject: Re: Is it possible not to use snprintf or any other stdio functionalities to throw std::logic_error in standard library containers?
>
>On 15/05/21 09:23 +0100, Jonathan Wakely via Libstdc++ wrote:
>>On Sat, 15 May 2021, 04:12 unlvsur unlvsur via Libstdc++, <
>>libstdc++@gcc.gnu.org> wrote:
>>
>>> The issue is that this will silently introduce dependency to stdio. On
>>> MinGW-w64 for example, any snprintf function call will bloat binary size
>>> for 70kb, that is even we shared linking with both msvcrt and libstdc++.
>>>
>>> I frequently see a random bloat because of that.
>>>
>>> By the way, it also hurts optimizations since compilers cannot merge them
>>> together.
>>>
>>> Better just throw an exception with “vector<T> out of bounds” instead of
>>> formatting subscriptor.
>>>
>>
>>
>>I can make that depend on the _GLIBCXX_VERBOSE macro.
>
>Where is the dependency on stdio coming from though? Formatting the
>exception string doesn't use stdio.
>
More information about the Libstdc++
mailing list