diff --git a/clang/include/clang/Basic/DiagnosticKinds.def b/clang/include/clang/Basic/DiagnosticKinds.def index e0218918c872..e0023e3667b3 100644 --- a/clang/include/clang/Basic/DiagnosticKinds.def +++ b/clang/include/clang/Basic/DiagnosticKinds.def @@ -877,6 +877,8 @@ DIAG(err_invalid_decimal_digit, ERROR, "invalid digit '%0' in decimal constant") DIAG(err_hexconstant_requires_exponent, ERROR, "hexadecimal floating constants require an exponent") +DIAG(ext_hexconstant_invalid, EXTENSION, + "hexadecimal floating constants are a C99 feature") DIAG(err_typecheck_subscript_value, ERROR, "subscripted value is neither array nor pointer") DIAG(err_typecheck_subscript, ERROR, diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp index 6c91e0e82d0c..fc90b4b00efb 100644 --- a/clang/lib/Lex/LiteralSupport.cpp +++ b/clang/lib/Lex/LiteralSupport.cpp @@ -354,18 +354,21 @@ 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') && PP.getLangOptions().HexFloats) { + if (*s == 'p' || *s == 'P') { const char *Exponent = s; s++; saw_exponent = true; if (*s == '+' || *s == '-') s++; // sign const char *first_non_digit = SkipDigits(s); - if (first_non_digit != s) { - s = first_non_digit; - } else { + if (first_non_digit == s) { Diag(PP.AdvanceToTokenCharacter(TokLoc, Exponent-ThisTokBegin), diag::err_exponent_has_no_digits); + return; } + s = first_non_digit; + + if (!PP.getLangOptions().HexFloats) + Diag(TokLoc, diag::ext_hexconstant_invalid); } else if (saw_period) { Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), diag::err_hexconstant_requires_exponent);