Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions clang/lib/Lex/LiteralSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
}

// Parse a potential octal literal prefix.
bool SawOctalPrefix = false;
bool SawOctalPrefix = false, IsSingleZero = false;
if ((c1 == 'O' || c1 == 'o') && (s[1] >= '0' && s[1] <= '7')) {
unsigned DiagId;
if (LangOpts.C2y)
Expand All @@ -1438,7 +1438,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
auto _ = llvm::make_scope_exit([&] {
// If we still have an octal value but we did not see an octal prefix,
// diagnose as being an obsolescent feature starting in C2y.
if (radix == 8 && LangOpts.C2y && !SawOctalPrefix && !hadError)
if (radix == 8 && LangOpts.C2y && !SawOctalPrefix && !hadError &&
!IsSingleZero)
Diags.Report(TokLoc, diag::warn_unprefixed_octal_deprecated);
});

Expand All @@ -1453,6 +1454,8 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
// anything, we leave the digit start where it was.
if (s != PossibleNewDigitStart)
DigitsBegin = PossibleNewDigitStart;
else
IsSingleZero = (s == ThisTokEnd); // Is the only thing we've seen a 0?

if (s == ThisTokEnd)
return; // Done, simple octal number like 01234
Expand Down
4 changes: 4 additions & 0 deletions clang/test/C/C2y/n3353.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ static const void *ptr = 0o0; /* ext-warning {{octal integer literals are a C2y
// 0 by itself is not deprecated, of course.
int k = 0;

// Test a preprocessor use of 0 by itself, which is also not deprecated.
#if 0
#endif

// Make sure there are no surprises with auto and type deduction. Promotion
// turns this into an 'int', and 'constexpr' implies 'const'.
constexpr auto l = 0o1234567; /* ext-warning {{octal integer literals are a C2y extension}}
Expand Down