[PATCH] Help compiler detect invalid code
François Dumont
frs.dumont@gmail.com
Wed Sep 25 20:40:00 GMT 2019
Some more tests have revealed a small problem in is_sorted test. It was
revealed by the Debug mode but not in a clean ways so for the moment I
prefer to fix it and I'll add a _neg test when Debug is able to report
it correctly.
I've also added a _neg test for equal which doesn't need Debug mode.
OK to commit ?
François
On 9/20/19 7:08 AM, François Dumont wrote:
> 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: 9443 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190925/16ab5a8f/attachment.bin>
More information about the Libstdc++
mailing list