File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -1420,7 +1420,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
14201420 }
14211421
14221422 // Parse a potential octal literal prefix.
1423- bool SawOctalPrefix = false ;
1423+ bool SawOctalPrefix = false , IsNakedZero = false ;
14241424 if ((c1 == ' O' || c1 == ' o' ) && (s[1 ] >= ' 0' && s[1 ] <= ' 7' )) {
14251425 unsigned DiagId;
14261426 if (LangOpts.C2y )
@@ -1438,7 +1438,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
14381438 auto _ = llvm::make_scope_exit ([&] {
14391439 // If we still have an octal value but we did not see an octal prefix,
14401440 // diagnose as being an obsolescent feature starting in C2y.
1441- if (radix == 8 && LangOpts.C2y && !SawOctalPrefix && !hadError)
1441+ if (radix == 8 && LangOpts.C2y && !SawOctalPrefix && !hadError &&
1442+ !IsNakedZero)
14421443 Diags.Report (TokLoc, diag::warn_unprefixed_octal_deprecated);
14431444 });
14441445
@@ -1453,6 +1454,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
14531454 // anything, we leave the digit start where it was.
14541455 if (s != PossibleNewDigitStart)
14551456 DigitsBegin = PossibleNewDigitStart;
1457+ else
1458+ IsNakedZero = s == ThisTokEnd; // Is the only thing we've seen a 0?
14561459
14571460 if (s == ThisTokEnd)
14581461 return ; // Done, simple octal number like 01234
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ static const void *ptr = 0o0; /* ext-warning {{octal integer literals are a C2y
4646// 0 by itself is not deprecated, of course.
4747int k = 0 ;
4848
49+ // Test a preprocessor use of 0 by itself, which is also not deprecated.
50+ #if 0
51+ #endif
52+
4953// Make sure there are no surprises with auto and type deduction. Promotion
5054// turns this into an 'int', and 'constexpr' implies 'const'.
5155constexpr auto l = 0 o1234567 ; /* ext-warning {{octal integer literals are a C2y extension}}
You can’t perform that action at this time.
0 commit comments