[PATCH] Help compiler detect invalid code

François Dumont frs.dumont@gmail.com
Fri Sep 20 05:08:00 GMT 2019


I already realized that previous patch will be too controversial to be 
accepted.

In this new version I just implement a real memmove in __memmove so that 
in copy_backward there is no need for a shortcut to a more defensive code.

I'll see if in Debug mode I can do something.

François


On 9/19/19 10:27 PM, François Dumont wrote:
> Hi
>
>     I start working on making recently added constexpr tests to work 
> in Debug mode.
>
>     It appears that the compiler is able to detect code mistakes 
> pretty well as long we don't try to hide the code intention with a 
> defensive approach. This is why I'd like to propose to replace '__n > 
> 0' conditions with '__n != 0'.
>
>     The result is demonstrated by the constexpr_neg.cc tests. What do 
> you think ?
>
>     * include/bits/stl_algobase.h (__memmove): Return _Tp*.
>     (__memmove): Loop as long as __n is not 0.
>     (__copy_move<>::__copy_m): Likewise.
>     (__copy_move_backward<>::__copy_move_b): Likewise.
>     * testsuite/25_algorithms/copy/constexpr.cc: Add check on copied 
> values.
>     * testsuite/25_algorithms/copy_backward/constexpr.cc: Likewise.
>     * testsuite/25_algorithms/copy/constexpr_neg.cc: New.
>     * testsuite/25_algorithms/copy_backward/constexpr.cc: New.
>
>     I'll submit the patch to fix Debug mode depending on the decision 
> for this one.
>
> François
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: constexpr_algo.patch
Type: text/x-patch
Size: 7195 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190920/29ffaedf/attachment.bin>


More information about the Libstdc++ mailing list