#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"
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) {
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':
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);
}
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
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