This is an archive of the discontinued LLVM Phabricator instance.

Implement http://wg21.link/P0426 Constexpr for std::char_traits
ClosedPublic

Authored by mclow.lists on Jan 9 2017, 11:20 AM.

Details

Summary

Make assign/length/find/compare for std::char_traits constexpr.

This makes using string_views at compile time easier.

Use the compiler intrinsics when available.
Note that __builtin_memchr is not really appropriate, since it returns a void *.
Sadly, this turns a bunch of code into "a twisty little maze of ifdefs, all different", but oh well.

Diff Detail

Event Timeline

mclow.lists retitled this revision from to Implement http://wg21.link/P0426 Constexpr for std::char_traits.
mclow.lists updated this object.
mclow.lists added reviewers: EricWF, rsmith.
mclow.lists added a subscriber: cfe-commits.
mclow.lists added inline comments.
include/__string
261

I will remove this block before committing.

rsmith added inline comments.Jan 9 2017, 11:52 AM
include/__string
248

We can add another builtin to Clang to support this case if you'd like. (There's also a way to get __builtin_memchr to work here using a __builtin_constant_p conditional expression to enable constant folding -- http://melpon.org/wandbox/permlink/0ob1n4a3zv1Kt3Ds -- but from discussion on IRC it sounds like Marshall is not happy about that approach.)

mclow.lists accepted this revision.Jan 11 2017, 8:48 PM
mclow.lists added a reviewer: mclow.lists.

revision 291741

This revision is now accepted and ready to land.Jan 11 2017, 8:48 PM
mclow.lists closed this revision.Feb 13 2017, 1:06 PM

Landed as r291741, r291742 and r293154.