Skip to content

Commit 4137309

Browse files
MitalAshokcor3ntin
andauthored
[Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 character literals in C23 (#97210)
Co-authored-by: cor3ntin <[email protected]>
1 parent cf1ad28 commit 4137309

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ Improvements to Clang's diagnostics
278278
- The lifetimebound and GSL analysis in clang are coherent, allowing clang to
279279
detect more use-after-free bugs. (#GH100549).
280280

281+
- Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.
282+
281283
Improvements to Clang's time-trace
282284
----------------------------------
283285

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def warn_cxx98_compat_unicode_literal : Warning<
283283
def warn_cxx14_compat_u8_character_literal : Warning<
284284
"unicode literals are incompatible with C++ standards before C++17">,
285285
InGroup<CXXPre17Compat>, DefaultIgnore;
286+
def warn_c17_compat_u8_character_literal : Warning<
287+
"unicode literals are incompatible with C standards before C23">,
288+
InGroup<CPre23Compat>, DefaultIgnore;
286289
def warn_cxx11_compat_user_defined_literal : Warning<
287290
"identifier after literal will be treated as a user-defined literal suffix "
288291
"in C++11">, InGroup<CXX11Compat>, DefaultIgnore;

clang/lib/Lex/Lexer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,9 @@ bool Lexer::LexCharConstant(Token &Result, const char *CurPtr,
24282428
? diag::warn_cxx98_compat_unicode_literal
24292429
: diag::warn_c99_compat_unicode_literal);
24302430
else if (Kind == tok::utf8_char_constant)
2431-
Diag(BufferPtr, diag::warn_cxx14_compat_u8_character_literal);
2431+
Diag(BufferPtr, LangOpts.CPlusPlus
2432+
? diag::warn_cxx14_compat_u8_character_literal
2433+
: diag::warn_c17_compat_u8_character_literal);
24322434
}
24332435

24342436
char C = getAndAdvanceChar(CurPtr, Result);

clang/test/Sema/pre-c2x-compat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
// RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -pedantic -fsyntax-only -verify
22

33
int digit_seps = 123'456; // expected-warning {{digit separators are incompatible with C standards before C23}}
4+
unsigned char u8_char = u8'x'; // expected-warning {{unicode literals are incompatible with C standards before C23}}

0 commit comments

Comments
 (0)