diff options
author | Alexis Hunt <alercah@gmail.com> | 2010-01-10 23:37:56 +0000 |
---|---|---|
committer | Alexis Hunt <alercah@gmail.com> | 2010-01-10 23:37:56 +0000 |
commit | 91b78382b51bb19e4023da4ef1818f146b7018dc (patch) | |
tree | 57b662e6a2f64cecafd85c903a5e65f6ca471bd6 /clang/lib/Lex | |
parent | 504a6ae83ee2a8d9ce7e6b470efc96822be3b2ed (diff) | |
download | bcm5719-llvm-91b78382b51bb19e4023da4ef1818f146b7018dc.tar.gz bcm5719-llvm-91b78382b51bb19e4023da4ef1818f146b7018dc.zip |
Do not parse hexadecimal floating point literals in C++0x mode because they are
incompatible with user-defined literals, specifically with the following form:
0x1p+1
The preprocessing-number token extends only as far as the 'p'; the '+' is not
included. Previously we could get away with this extension as p was an invalid
suffix, but now with user-defined literals, 'p' might well be a valid suffix
and we are forced to consider it as such.
This patch also adds a warning in non-0x C++ modes telling the user that
this extension is incompatible with C++0x that is enabled by default
(previously and with other languages, we warn only with a compliance
option such as -pedantic).
llvm-svn: 93135
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r-- | clang/lib/Lex/Lexer.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Lex/LiteralSupport.cpp | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp index d5a46433c36..d82f8fcf858 100644 --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -724,7 +724,8 @@ void Lexer::LexNumericConstant(Token &Result, const char *CurPtr) { return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result)); // If we have a hex FP constant, continue. - if ((C == '-' || C == '+') && (PrevCh == 'P' || PrevCh == 'p')) + if ((C == '-' || C == '+') && (PrevCh == 'P' || PrevCh == 'p') && + (!PP || !PP->getLangOptions().CPlusPlus0x)) return LexNumericConstant(Result, ConsumeChar(CurPtr, Size, Result)); // Update the location of token as well as BufferPtr. diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 9aaa82d6263..5cd54975055 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -458,7 +458,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { } // A binary exponent can appear with or with a '.'. If dotted, the // binary exponent is required. - if (*s == 'p' || *s == 'P') { + if ((*s == 'p' || *s == 'P') && !PP.getLangOptions().CPlusPlus0x) { const char *Exponent = s; s++; saw_exponent = true; @@ -472,7 +472,12 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { } s = first_non_digit; - if (!PP.getLangOptions().HexFloats) + // In C++0x, we cannot support hexadecmial floating literals because + // they conflict with user-defined literals, so we warn in previous + // versions of C++ by default. + if (PP.getLangOptions().CPlusPlus) + PP.Diag(TokLoc, diag::ext_hexconstant_cplusplus); + else if (!PP.getLangOptions().HexFloats) PP.Diag(TokLoc, diag::ext_hexconstant_invalid); } else if (saw_period) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), |