This is an archive of the discontinued LLVM Phabricator instance.

[Support] Add format_provider for StringLiteral
ClosedPublic

Authored by labath on Feb 13 2017, 10:01 AM.

Details

Summary

Even though it inherits from StringRef, we need to mention it
explicitly, as the formatter selection mechanism does not take
inheritance into account.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Feb 13 2017, 10:01 AM
dblaikie added inline comments.
include/llvm/Support/FormatProviders.h
49–50 ↗(On Diff #88219)

Perhaps this should use "is_convertible" which would match the implementation (well, not quite - the implementation should probably use "StringRef S = V" rather than StringRef S(V))?

zturner added inline comments.Feb 13 2017, 12:59 PM
include/llvm/Support/FormatProviders.h
49–50 ↗(On Diff #88219)

If it works I'm all for simplifying. Need to be careful with potentially overlapping conditions though.

labath updated this revision to Diff 88342.Feb 14 2017, 3:40 AM

Using is_convertible will work right now. What will this prevent is someone
defining their own format_provider on a class which has a conversion operator
for StringRef. I've debated this with myself a bit. On one hand, it adds more
predictability (if something behaves enough like StringRef that in can be
converted to one, it should also be formatted like it). On the other hand, I'm
sure somebody somewhere will invent a case where it still makes sense to do
that.

But I suppose we can cross that bridge when we come to it.

Looks good to me - but please wait for Zach to take a look & sign off.

This revision was automatically updated to reflect the committed changes.