Update diagnostics now that hexadecimal literals look likely to be part of C++17.

llvm-svn: 262753
This commit is contained in:
Richard Smith 2016-03-04 22:32:06 +00:00
parent ac92893a93
commit 560a3579b2
6 changed files with 50 additions and 20 deletions

View File

@ -175,10 +175,17 @@ def err_multichar_utf_character_literal : Error<
def err_exponent_has_no_digits : Error<"exponent has no digits">;
def ext_imaginary_constant : Extension<
"imaginary constants are a GNU extension">, InGroup<GNUImaginaryConstant>;
def err_hexconstant_requires: Error<
"hexadecimal floating constants require %select{an exponent|a significand}0">;
def ext_hexconstant_invalid : Extension<
def err_hex_constant_requires : Error<
"hexadecimal floating %select{constant|literal}0 requires "
"%select{an exponent|a significand}1">;
def ext_hex_constant_invalid : Extension<
"hexadecimal floating constants are a C99 feature">, InGroup<C99>;
def ext_hex_literal_invalid : Extension<
"hexadecimal floating literals are a C++1z feature">, InGroup<CXX1z>;
def warn_cxx1z_hex_literal : Warning<
"hexidecimal floating literals are incompatible with "
"C++ standards before C++1z">,
InGroup<CXXPre1zCompatPedantic>, DefaultIgnore;
def ext_binary_literal : Extension<
"binary integer literals are a GNU extension">, InGroup<GNUBinaryLiteral>;
def ext_binary_literal_cxx14 : Extension<

View File

@ -125,11 +125,11 @@ LANGSTANDARD(gnucxx14, "gnu++14",
LANGSTANDARD(cxx1z, "c++1z",
"Working draft for ISO C++ 2017",
LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z |
Digraphs)
Digraphs | HexFloat)
LANGSTANDARD(gnucxx1z, "gnu++1z",
"Working draft for ISO C++ 2017 with GNU extensions",
LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z |
Digraphs | GNUMode)
Digraphs | HexFloat | GNUMode)
// OpenCL
LANGSTANDARD(opencl, "cl",

View File

@ -1607,14 +1607,15 @@ bool Lexer::LexNumericConstant(Token &Result, const char *CurPtr) {
// If we have a hex FP constant, continue.
if ((C == '-' || C == '+') && (PrevCh == 'P' || PrevCh == 'p')) {
// Outside C99, we accept hexadecimal floating point numbers as a
// Outside C99 and C++17, we accept hexadecimal floating point numbers as a
// not-quite-conforming extension. Only do so if this looks like it's
// actually meant to be a hexfloat, and not if it has a ud-suffix.
bool IsHexFloat = true;
if (!LangOpts.C99) {
if (!isHexaLiteral(BufferPtr, LangOpts))
IsHexFloat = false;
else if (std::find(BufferPtr, CurPtr, '_') != CurPtr)
else if (!getLangOpts().CPlusPlus1z &&
std::find(BufferPtr, CurPtr, '_') != CurPtr)
IsHexFloat = false;
}
if (IsHexFloat)

View File

@ -797,7 +797,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
if (!HasSignificandDigits) {
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin),
diag::err_hexconstant_requires) << 1;
diag::err_hex_constant_requires)
<< PP.getLangOpts().CPlusPlus << 1;
hadError = true;
return;
}
@ -821,10 +822,15 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
s = first_non_digit;
if (!PP.getLangOpts().HexFloats)
PP.Diag(TokLoc, diag::ext_hexconstant_invalid);
PP.Diag(TokLoc, PP.getLangOpts().CPlusPlus
? diag::ext_hex_literal_invalid
: diag::ext_hex_constant_invalid);
else if (PP.getLangOpts().CPlusPlus1z)
PP.Diag(TokLoc, diag::warn_cxx1z_hex_literal);
} else if (saw_period) {
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin),
diag::err_hexconstant_requires) << 0;
PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin),
diag::err_hex_constant_requires)
<< PP.getLangOpts().CPlusPlus << 0;
hadError = true;
}
return;

View File

@ -48,7 +48,7 @@ namespace floating {
float r = 0.'0e1; // expected-error {{digit separator cannot appear at start of digit sequence}}
float s = 0.0'e1; // expected-error {{digit separator cannot appear at end of digit sequence}}
float t = 0.0e'1; // expected-error {{digit separator cannot appear at start of digit sequence}}
float u = 0x.'p1f; // expected-error {{hexadecimal floating constants require a significand}}
float u = 0x.'p1f; // expected-error {{hexadecimal floating literal requires a significand}}
float v = 0e'f; // expected-error {{exponent has no digits}}
float w = 0x0p'f; // expected-error {{exponent has no digits}}
}

View File

@ -1,15 +1,31 @@
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify -pedantic %s
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -pedantic %s
float f = 0x1p+1; // expected-warning{{hexadecimal floating constants are a C99 feature}}
double e = 0x.p0; //expected-error{{hexadecimal floating constants require a significand}}
double d = 0x.2p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
float g = 0x1.2p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
double h = 0x1.p2; // expected-warning{{hexadecimal floating constants are a C99 feature}}
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify -pedantic %s
// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify -pedantic %s
double e = 0x.p0; // expected-error-re {{hexadecimal floating {{constant|literal}} requires a significand}}
float f = 0x1p+1;
double d = 0x.2p2;
float g = 0x1.2p2;
double h = 0x1.p2;
#if __cplusplus <= 201402L
// expected-warning@-5 {{hexadecimal floating literals are a C++1z feature}}
// expected-warning@-5 {{hexadecimal floating literals are a C++1z feature}}
// expected-warning@-5 {{hexadecimal floating literals are a C++1z feature}}
// expected-warning@-5 {{hexadecimal floating literals are a C++1z feature}}
#endif
// PR12717: In order to minimally diverge from the C++ standard, we do not lex
// 'p[+-]' as part of a pp-number unless the token starts 0x and doesn't contain
// an underscore.
double i = 0p+3; // expected-error{{invalid suffix 'p' on integer constant}}
double i = 0p+3; // expected-error {{invalid suffix 'p' on integer constant}}
#define PREFIX(x) foo ## x
double foo0p = 1, j = PREFIX(0p+3); // ok
double k = 0x42_amp+3; // expected-error-re{{{{invalid suffix '_amp' on integer constant|no matching literal operator for call to 'operator""_amp'}}}}
double k = 0x42_amp+3;
#if __cplusplus > 201402L
// expected-error@-2 {{no matching literal operator for call to 'operator""_amp+3'}}
#elif __cplusplus >= 201103L
// expected-error@-4 {{no matching literal operator for call to 'operator""_amp'}}
#else
// expected-error@-6 {{invalid suffix '_amp' on integer constant}}
#endif