Skip to content

Commit 8366dc2

Browse files
authored
[clang] Don't warn on zero literals with -std=c2y (#149688)
Fixes #149669; the old check compared with the end of the literal, but we can just check that after parsing digits, we're pointing to one character past the token start.
1 parent 04e5e64 commit 8366dc2

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

clang/lib/Lex/LiteralSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
14671467
if (s != PossibleNewDigitStart)
14681468
DigitsBegin = PossibleNewDigitStart;
14691469
else
1470-
IsSingleZero = (s == ThisTokEnd); // Is the only thing we've seen a 0?
1470+
IsSingleZero = (s == ThisTokBegin + 1);
14711471

14721472
if (s == ThisTokEnd)
14731473
return; // Done, simple octal number like 01234

clang/test/C/C2y/n3353.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ static const void *ptr = 0o0; /* ext-warning {{octal integer literals are a C2y
4444
#endif
4545

4646
// 0 by itself is not deprecated, of course.
47-
int k = 0;
47+
int k1 = 0;
48+
unsigned int k2 = 0u;
49+
long k3 = 0l;
50+
unsigned long k4 = 0ul;
51+
long long k5 = 0ll;
52+
unsigned long long k6 = 0ull;
4853

4954
// Test a preprocessor use of 0 by itself, which is also not deprecated.
5055
#if 0
@@ -65,7 +70,6 @@ static_assert(__extension__ _Generic(typeof(l), const int : 1, default : 0)); //
6570

6671
// Note that 0o by itself is an invalid literal.
6772
int m = 0o; /* expected-error {{invalid suffix 'o' on integer constant}}
68-
c2y-warning {{octal literals without a '0o' prefix are deprecated}}
6973
*/
7074

7175
// Ensure negation works as expected.
@@ -83,13 +87,11 @@ int n = 0o18; /* expected-error {{invalid digit '8' in octal constant}}
8387
cpp-warning {{octal integer literals are a Clang extension}}
8488
*/
8589
int o1 = 0o8; /* expected-error {{invalid suffix 'o8' on integer constant}}
86-
c2y-warning {{octal literals without a '0o' prefix are deprecated}}
8790
*/
8891
// FIXME: however, it matches the behavior for hex literals in terms of the
8992
// error reported. Unfortunately, we then go on to think 0 is an octal literal
9093
// without a prefix, which is again a bit confusing.
9194
int o2 = 0xG; /* expected-error {{invalid suffix 'xG' on integer constant}}
92-
c2y-warning {{octal literals without a '0o' prefix are deprecated}}
9395
*/
9496

9597
// Show that floating-point suffixes on octal literals are rejected.
@@ -130,7 +132,6 @@ constexpr int p = 0o0'1'2'3'4'5'6'7; /* compat-warning {{octal integer literals
130132
*/
131133
static_assert(p == 01234567); // c2y-warning {{octal literals without a '0o' prefix are deprecated}}
132134
int q = 0o'0'1; /* expected-error {{invalid suffix 'o'0'1' on integer constant}}
133-
c2y-warning {{octal literals without a '0o' prefix are deprecated}}
134135
*/
135136

136137
#define M 0o123

0 commit comments

Comments
 (0)