[PATCH] Finish implementing P0426R1 "Constexpr for std::char_traits" for C++17

Jonathan Wakely jwakely@redhat.com
Tue Jun 13 15:57:00 GMT 2017


On 12/06/17 23:28 +0100, Pedro Alves wrote:
>On 06/05/2017 03:27 PM, Jonathan Wakely wrote:
>
>> Pedro, this is OK for trunk now we're in stage 1. Please go ahead and
>> commit it - thanks.
>
>Thanks Jonathan.  I've pushed it in now.
>
>>
>> It's probably safe for gcc-7-branch too, but let's leave it on trunk
>> for a while first.
>
>OK.
>
>BTW, for extra thoroughness, to confirm we're handling both
>const & non-const arrays correctly, I had written this testsuite
>tweak too.  Would you like to have this in?

Yes please, this looks useful.


>@@ -98,7 +220,12 @@ static_assert( test_compare<std::char_traits<char32_t>>() );
> static_assert( test_length<std::char_traits<char32_t>>() );
> static_assert( test_find<std::char_traits<char32_t>>() );
>
>-struct C { unsigned char c; };
>+struct C
>+{
>+  C() = default;
>+  constexpr C(auto c_) : c(c_) {}

Placeholder types as function parameters are non-standard, so this
would fail with -pedantic-errors.

How about:

struct C {
  constexpr C(unsigned char c_ = 0) : c(c_) { }
  unsigned char c;
};


>+  unsigned char c;
>+};
> constexpr bool operator==(const C& c1, const C& c2) { return c1.c == c2.c; }
> constexpr bool operator<(const C& c1, const C& c2) { return c1.c < c2.c; }
> static_assert( test_assign<std::char_traits<C>>() );
>-- 
>2.5.5
>
>



More information about the Libstdc++ mailing list