This is an archive of the discontinued LLVM Phabricator instance.

Enable C++2a Chrono Literals
ClosedPublic

Authored by erichkeane on Jul 18 2018, 12:52 PM.

Details

Summary

C++2a via http://wg21.link/p0355 permits the library
literals of 'd' and 'y'. This patch enables them in the
Lexer so that they can be properly parsed.

Note that 'd' gets confused with the hex character, so
modifications to how octal, binary, and decimal numbers are
parsed were required. Since this is simply making previously
invalid code legal, this should be fine.

Hex still greedily parses the 'd' as a hexit, since it would
a: violate [lex.ext]p1
b: break existing code.

Diff Detail

Repository
rC Clang

Event Timeline

erichkeane created this revision.Jul 18 2018, 12:52 PM

This looks ok to me - I'm assuming that somewhere there's a test for int foo = 0x123d, so we're sure that didn't get broken.

test/SemaCXX/cxx2a-user-defined-literals.cpp
9

Do you need string here, or is this a copy-pasto?

This looks ok to me - I'm assuming that somewhere there's a test for int foo = 0x123d, so we're sure that didn't get broken.

The hex_d SHOULD be testing that, it ensures that the RHS is an integer.

test/SemaCXX/cxx2a-user-defined-literals.cpp
9

Gah, good catch. I was testing something else briefly.

aaron.ballman added inline comments.
lib/Lex/LiteralSupport.cpp
815

Is it possible for the library to expose those outside of C++2a mode? We pass true for the C++14 cases, so I'm wondering about tying it to C++2a explicitly.

test/SemaCXX/cxx2a-user-defined-literals.cpp
2

Can you drop the svn properties, please?

13

Is this needed?

erichkeane added inline comments.Jul 19 2018, 6:01 AM
lib/Lex/LiteralSupport.cpp
815

In the C++14 cases, we return true because we've checked C++14 mode on line 805. I was hoping to do that for consistencies sake. Depending on your opinion, bringing 805 down to 812/813/814 (checking inline) might be a good idea.

According to the tests, 'sv' (string view) was the only one for C++17, but it wasn't really necessary to check here since it is only allowed on strings and not on integer literals.

test/SemaCXX/cxx2a-user-defined-literals.cpp
2

Yep, will do :)

13

It is, in fact, not required.

erichkeane marked 4 inline comments as done.

@aaron.ballman s comments.

test/SemaCXX/cxx2a-user-defined-literals.cpp
24

Of course, the '9' in these two lines is now wrong... I'll fix it in my local copy.

erichkeane added inline comments.Jul 19 2018, 6:22 AM
test/SemaCXX/cxx2a-user-defined-literals.cpp
24

Actually not, since it was above the removed line... I need to stop working before my first caffeine infusion...

aaron.ballman accepted this revision.Jul 19 2018, 6:40 AM

LGTM!

lib/Lex/LiteralSupport.cpp
815

Ahh, I see what's going on now. Thank you, this looks fine to me.

This revision is now accepted and ready to land.Jul 19 2018, 6:40 AM
This revision was automatically updated to reflect the committed changes.