[cfe-commits] r93135 - in /cfe/trunk: include/clang/Basic/DiagnosticLexKinds.td lib/Lex/Lexer.cpp lib/Lex/LiteralSupport.cpp test/Lexer/hexfloat.cpp
Sean Hunt
rideau3 at gmail.com
Sun Jan 10 15:37:56 PST 2010
Author: coppro
Date: Sun Jan 10 17:37:56 2010
New Revision: 93135
URL: http://llvm.org/viewvc/llvm-project?rev=93135&view=rev
Log:
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).
Added:
cfe/trunk/test/Lexer/hexfloat.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/LiteralSupport.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=93135&r1=93134&r2=93135&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Sun Jan 10 17:37:56 2010
@@ -84,6 +84,9 @@
def ext_imaginary_constant : Extension<"imaginary constants are an extension">;
def err_hexconstant_requires_exponent : Error<
"hexadecimal floating constants require an exponent">;
+def ext_hexconstant_cplusplus : ExtWarn<
+ "hexadecimal floating constants are a C99 feature that is incompatible with "
+ "C++0x">;
def ext_hexconstant_invalid : Extension<
"hexadecimal floating constants are a C99 feature">;
def ext_binary_literal : Extension<
Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=93135&r1=93134&r2=93135&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Sun Jan 10 17:37:56 2010
@@ -724,7 +724,8 @@
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.
Modified: cfe/trunk/lib/Lex/LiteralSupport.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/LiteralSupport.cpp?rev=93135&r1=93134&r2=93135&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/LiteralSupport.cpp (original)
+++ cfe/trunk/lib/Lex/LiteralSupport.cpp Sun Jan 10 17:37:56 2010
@@ -458,7 +458,7 @@
}
// 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 @@
}
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),
Added: cfe/trunk/test/Lexer/hexfloat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/hexfloat.cpp?rev=93135&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/hexfloat.cpp (added)
+++ cfe/trunk/test/Lexer/hexfloat.cpp Sun Jan 10 17:37:56 2010
@@ -0,0 +1,8 @@
+//RUN: %clang_cc1 -fsyntax-only -verify
+//RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify
+
+#ifndef __GXX_EXPERIMENTAL_CXX0X__
+float f = 0x1p+1; // expected-warning {{incompatible with C++0x}}
+#else
+float f = 0x1p+1; // expected-warning {{invalid suffix}}
+#endif
More information about the cfe-commits
mailing list