aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Herchen <timothy.herchen@gmail.com>2025-07-21 09:15:09 -0700
committerGitHub <noreply@github.com>2025-07-21 12:15:09 -0400
commit8366dc207a2e6b50cb8afe2d98fca68bd78bd0fa (patch)
treea00ac2382e9e8e8803c248ad72039c412eb8d1e8
parent04e5e643f526090ec872c0e505c487918992e21d (diff)
downloadllvm-8366dc207a2e6b50cb8afe2d98fca68bd78bd0fa.zip
llvm-8366dc207a2e6b50cb8afe2d98fca68bd78bd0fa.tar.gz
llvm-8366dc207a2e6b50cb8afe2d98fca68bd78bd0fa.tar.bz2
[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.
-rw-r--r--clang/lib/Lex/LiteralSupport.cpp2
-rw-r--r--clang/test/C/C2y/n3353.c11
2 files changed, 7 insertions, 6 deletions
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index a62508e..5b08d7f 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1467,7 +1467,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
if (s != PossibleNewDigitStart)
DigitsBegin = PossibleNewDigitStart;
else
- IsSingleZero = (s == ThisTokEnd); // Is the only thing we've seen a 0?
+ IsSingleZero = (s == ThisTokBegin + 1);
if (s == ThisTokEnd)
return; // Done, simple octal number like 01234
diff --git a/clang/test/C/C2y/n3353.c b/clang/test/C/C2y/n3353.c
index cd61cbf..a2e08cf 100644
--- a/clang/test/C/C2y/n3353.c
+++ b/clang/test/C/C2y/n3353.c
@@ -44,7 +44,12 @@ static const void *ptr = 0o0; /* ext-warning {{octal integer literals are a C2y
#endif
// 0 by itself is not deprecated, of course.
-int k = 0;
+int k1 = 0;
+unsigned int k2 = 0u;
+long k3 = 0l;
+unsigned long k4 = 0ul;
+long long k5 = 0ll;
+unsigned long long k6 = 0ull;
// Test a preprocessor use of 0 by itself, which is also not deprecated.
#if 0
@@ -65,7 +70,6 @@ static_assert(__extension__ _Generic(typeof(l), const int : 1, default : 0)); //
// Note that 0o by itself is an invalid literal.
int m = 0o; /* expected-error {{invalid suffix 'o' on integer constant}}
- c2y-warning {{octal literals without a '0o' prefix are deprecated}}
*/
// Ensure negation works as expected.
@@ -83,13 +87,11 @@ int n = 0o18; /* expected-error {{invalid digit '8' in octal constant}}
cpp-warning {{octal integer literals are a Clang extension}}
*/
int o1 = 0o8; /* expected-error {{invalid suffix 'o8' on integer constant}}
- c2y-warning {{octal literals without a '0o' prefix are deprecated}}
*/
// FIXME: however, it matches the behavior for hex literals in terms of the
// error reported. Unfortunately, we then go on to think 0 is an octal literal
// without a prefix, which is again a bit confusing.
int o2 = 0xG; /* expected-error {{invalid suffix 'xG' on integer constant}}
- c2y-warning {{octal literals without a '0o' prefix are deprecated}}
*/
// 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
*/
static_assert(p == 01234567); // c2y-warning {{octal literals without a '0o' prefix are deprecated}}
int q = 0o'0'1; /* expected-error {{invalid suffix 'o'0'1' on integer constant}}
- c2y-warning {{octal literals without a '0o' prefix are deprecated}}
*/
#define M 0o123