[clang] 5d92d0b - Correctly diagnose use of long long literals w/o a suffix
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 17 04:56:47 PDT 2022
Author: Aaron Ballman
Date: 2022-09-17T07:55:10-04:00
New Revision: 5d92d0b0f86c2c4e0c6ebd7b1e2113337fec041d
URL: https://github.com/llvm/llvm-project/commit/5d92d0b0f86c2c4e0c6ebd7b1e2113337fec041d
DIFF: https://github.com/llvm/llvm-project/commit/5d92d0b0f86c2c4e0c6ebd7b1e2113337fec041d.diff
LOG: Correctly diagnose use of long long literals w/o a suffix
We would diagnose use of `long long` as an extension in C89 and C++98
modes when the user spelled the type `long long` or used the `LL`
literal suffix, but failed to diagnose when the literal had no suffix
but required a `long long` to represent the value.
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/C/drs/dr2xx.c
clang/test/CXX/drs/dr4xx.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ccc3204edd2d2..4c251d1dc6ed7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -168,6 +168,10 @@ Improvements to Clang's diagnostics
conditional operator, and for most binary operations. Type sugar is combined
in a way that strips the sugar which is
diff erent between terms, and preserves
those which are common.
+- Correctly diagnose use of an integer literal without a suffix whose
+ underlying type is ``long long`` or ``unsigned long long`` as an extension in
+ C89 mode . Clang previously only diagnosed if the literal had an explicit
+ ``LL`` suffix.
Non-comprehensive list of changes in this release
-------------------------------------------------
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 348eaad3dee94..e53c88b283b87 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3937,16 +3937,6 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
} else {
QualType Ty;
- // 'long long' is a C99 or C++11 feature.
- if (!getLangOpts().C99 && Literal.isLongLong) {
- if (getLangOpts().CPlusPlus)
- Diag(Tok.getLocation(),
- getLangOpts().CPlusPlus11 ?
- diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong);
- else
- Diag(Tok.getLocation(), diag::ext_c99_longlong);
- }
-
// 'z/uz' literals are a C++2b feature.
if (Literal.isSizeT)
Diag(Tok.getLocation(), getLangOpts().CPlusPlus
@@ -4113,6 +4103,15 @@ ExprResult Sema::ActOnNumericConstant(const Token &Tok, Scope *UDLScope) {
else if (AllowUnsigned)
Ty = Context.UnsignedLongLongTy;
Width = LongLongSize;
+
+ // 'long long' is a C99 or C++11 feature, whether the literal
+ // explicitly specified 'long long' or we needed the extra width.
+ if (getLangOpts().CPlusPlus)
+ Diag(Tok.getLocation(), getLangOpts().CPlusPlus11
+ ? diag::warn_cxx98_compat_longlong
+ : diag::ext_cxx11_longlong);
+ else if (!getLangOpts().C99)
+ Diag(Tok.getLocation(), diag::ext_c99_longlong);
}
}
diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c
index 6b87aace6a910..95d8eefaa2a99 100644
--- a/clang/test/C/drs/dr2xx.c
+++ b/clang/test/C/drs/dr2xx.c
@@ -448,9 +448,11 @@ void dr298(void) {
/* FIXME: These uses of the constants need a pedantic warning in C89 mode;
* we've picked a type that does not exist in C89.
*/
- (void)_Generic(9223372036854775808, /* expected-warning {{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}} */
+ (void)_Generic(9223372036854775808, /* expected-warning {{integer literal is too large to be represented in a signed integer type, interpreting as unsigned}}
+ c89only-warning {{'long long' is an extension when C99 mode is not enabled}}
+ */
unsigned long long : 1); /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
- (void)_Generic(9223372036854775807,
+ (void)_Generic(9223372036854775807, /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
long long : 1); /* c89only-warning {{'long long' is an extension when C99 mode is not enabled}} */
}
#endif /* __LLONG_WIDTH__ == 64 && __LONG_WIDTH__ < 64 */
diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index 16957dd9d0e39..4995e4de65d3f 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -1013,7 +1013,7 @@ namespace dr483 { // dr483: yes
int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
#if __cplusplus < 201103L
- // expected-error at -2 {{extension}}
+ // expected-error at -2 2{{extension}}
#endif
}
namespace cstdint {
More information about the cfe-commits
mailing list