Handle standard libraries that miss out the space when defining the standard
literal operators. Also, for now, allow the proposed C++1y "il", "i", and "if" suffixes too. (Will revert the latter if LWG decides not to go ahead with that change after all.) llvm-svn: 191274
This commit is contained in:
parent
0e08d7757b
commit
2a98862be2
|
@ -29,6 +29,7 @@
|
|||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Lex/CodeCompletionHandler.h"
|
||||
#include "clang/Lex/LexDiagnostic.h"
|
||||
#include "clang/Lex/LiteralSupport.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
|
@ -1638,12 +1639,33 @@ const char *Lexer::LexUDSuffix(Token &Result, const char *CurPtr,
|
|||
bool IsUDSuffix = false;
|
||||
if (C == '_')
|
||||
IsUDSuffix = true;
|
||||
else if (IsStringLiteral && C == 's' && getLangOpts().CPlusPlus1y) {
|
||||
// In C++1y, "s" is a valid ud-suffix for a string literal.
|
||||
unsigned NextSize;
|
||||
if (!isIdentifierBody(getCharAndSizeNoWarn(CurPtr + Size, NextSize,
|
||||
getLangOpts())))
|
||||
IsUDSuffix = true;
|
||||
else if (IsStringLiteral && getLangOpts().CPlusPlus1y) {
|
||||
// In C++1y, we need to look ahead a few characters to see if this is a
|
||||
// valid suffix for a string literal or a numeric literal (this could be
|
||||
// the 'operator""if' defining a numeric literal operator).
|
||||
const int MaxStandardSuffixLength = 3;
|
||||
char Buffer[MaxStandardSuffixLength] = { C };
|
||||
unsigned Consumed = Size;
|
||||
unsigned Chars = 1;
|
||||
while (true) {
|
||||
unsigned NextSize;
|
||||
char Next = getCharAndSizeNoWarn(CurPtr + Consumed, NextSize,
|
||||
getLangOpts());
|
||||
if (!isIdentifierBody(Next)) {
|
||||
// End of suffix. Check whether this is on the whitelist.
|
||||
IsUDSuffix = (Chars == 1 && Buffer[0] == 's') ||
|
||||
NumericLiteralParser::isValidUDSuffix(
|
||||
getLangOpts(), StringRef(Buffer, Chars));
|
||||
break;
|
||||
}
|
||||
|
||||
if (Chars == MaxStandardSuffixLength)
|
||||
// Too long: can't be a standard suffix.
|
||||
break;
|
||||
|
||||
Buffer[Chars++] = Next;
|
||||
Consumed += NextSize;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsUDSuffix) {
|
||||
|
|
|
@ -604,6 +604,9 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling,
|
|||
break;
|
||||
}
|
||||
}
|
||||
// "i", "if", and "il" are user-defined suffixes in C++1y.
|
||||
if (PP.getLangOpts().CPlusPlus1y && *s == 'i')
|
||||
break;
|
||||
// fall through.
|
||||
case 'j':
|
||||
case 'J':
|
||||
|
@ -665,9 +668,11 @@ bool NumericLiteralParser::isValidUDSuffix(const LangOptions &LangOpts,
|
|||
return false;
|
||||
|
||||
// In C++1y, "s", "h", "min", "ms", "us", and "ns" are used in the library.
|
||||
// Per tweaked N3660, "il", "i", and "if" are also used in the library.
|
||||
return llvm::StringSwitch<bool>(Suffix)
|
||||
.Cases("h", "min", "s", true)
|
||||
.Cases("ms", "us", "ns", true)
|
||||
.Cases("il", "i", "if", true)
|
||||
.Default(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,15 +8,23 @@ namespace std {
|
|||
using size_t = decltype(sizeof(0));
|
||||
|
||||
struct duration {};
|
||||
duration operator"" ns(unsigned long long);
|
||||
duration operator"" us(unsigned long long);
|
||||
duration operator"" ms(unsigned long long);
|
||||
duration operator"" s(unsigned long long);
|
||||
duration operator"" min(unsigned long long);
|
||||
duration operator"" h(unsigned long long);
|
||||
duration operator""ns(unsigned long long);
|
||||
duration operator""us(unsigned long long);
|
||||
duration operator""ms(unsigned long long);
|
||||
duration operator""s(unsigned long long);
|
||||
duration operator""min(unsigned long long);
|
||||
duration operator""h(unsigned long long);
|
||||
|
||||
struct string {};
|
||||
string operator"" s(const char*, size_t);
|
||||
string operator""s(const char*, size_t);
|
||||
|
||||
template<typename T> struct complex {};
|
||||
complex<float> operator""if(long double);
|
||||
complex<float> operator""if(unsigned long long);
|
||||
complex<double> operator""i(long double);
|
||||
complex<double> operator""i(unsigned long long);
|
||||
complex<long double> operator""il(long double);
|
||||
complex<long double> operator""il(unsigned long long);
|
||||
}
|
||||
|
||||
#else
|
||||
|
@ -29,4 +37,8 @@ char error = 'x's; // expected-error {{invalid suffix}} expected-error {{expecte
|
|||
int _1z = 1z; // expected-error {{invalid suffix}}
|
||||
int _1b = 1b; // expected-error {{invalid digit}}
|
||||
|
||||
complex<float> cf1 = 1if, cf2 = 2.if, cf3 = 0x3if;
|
||||
complex<double> cd1 = 1i, cd2 = 2.i, cd3 = 0b0110101i;
|
||||
complex<long double> cld1 = 1il, cld2 = 2.il, cld3 = 0047il;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue