Skip to content

Commit 5e092e7

Browse files
committed
Use -Wcharacter-conversion, add it to -Wconversion, make it a feature for libcxx
1 parent 2df2d48 commit 5e092e7

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Improvements to Clang's diagnostics
503503
- ``-Wreserved-identifier`` now fires on reserved parameter names in a function
504504
declaration which is not a definition.
505505

506-
- A new ``-Wimplicit-unicode-conversion`` warns where comparing or implicitly converting
506+
- A new ``-Wcharacter-conversion`` warns where comparing or implicitly converting
507507
between different Unicode character types (``char8_t``, ``char16_t``, ``char32_t``).
508508
This warning only triggers in C++ as these types are aliases in C. (#GH138526)
509509

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def EnumConversion : DiagGroup<"enum-conversion",
111111
ImplicitEnumEnumCast,
112112
EnumFloatConversion,
113113
EnumCompareConditional]>;
114-
def ImplicitUnicodeConversion : DiagGroup<"implicit-unicode-conversion">;
114+
def CharacterConversion : DiagGroup<"character-conversion">;
115115
def DeprecatedOFast : DiagGroup<"deprecated-ofast">;
116116
def ObjCSignedCharBoolImplicitIntConversion :
117117
DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
@@ -1074,6 +1074,7 @@ def Parentheses : DiagGroup<"parentheses",
10741074
// - __null-to-integer conversion warnings are on by default
10751075
def Conversion : DiagGroup<"conversion",
10761076
[BoolConversion,
1077+
CharacterConversion,
10771078
ConstantConversion,
10781079
EnumConversion,
10791080
BitFieldEnumConversion,

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,25 +4360,25 @@ def warn_address_of_reference_bool_conversion : Warning<
43604360
def warn_impcast_unicode_char_type
43614361
: Warning<"implicit conversion from %0 to %1 may change the meaning of the "
43624362
"represented code unit">,
4363-
InGroup<ImplicitUnicodeConversion>;
4363+
InGroup<CharacterConversion>;
43644364
def warn_impcast_unicode_precision
43654365
: Warning<"implicit conversion from %0 to %1 may lose precision and change "
43664366
"the meaning of the represented code unit">,
4367-
InGroup<ImplicitUnicodeConversion>;
4367+
InGroup<CharacterConversion>;
43684368
def warn_impcast_unicode_char_type_constant
43694369
: Warning<"implicit conversion from %0 to %1 changes the meaning of the "
43704370
"%select{code unit|codepoint}2 '%3'">,
4371-
InGroup<ImplicitUnicodeConversion>;
4371+
InGroup<CharacterConversion>;
43724372

43734373
def warn_comparison_unicode_mixed_types
43744374
: Warning<"comparing values of different Unicode code unit types %0 and %1 "
43754375
"may compare different codepoints">,
4376-
InGroup<ImplicitUnicodeConversion>;
4376+
InGroup<CharacterConversion>;
43774377

43784378
def warn_comparison_unicode_mixed_types_constant
43794379
: Warning<"comparing values of different Unicode code unit types %0 and %1 "
43804380
"compares unrelated code units '%2' and '%3'">,
4381-
InGroup<ImplicitUnicodeConversion>;
4381+
InGroup<CharacterConversion>;
43824382

43834383
def warn_xor_used_as_pow : Warning<
43844384
"result of '%0' is %1; did you mean exponentiation?">,
@@ -6843,7 +6843,7 @@ def err_counted_by_on_incomplete_type_on_use : Error <
68436843

68446844
def note_counted_by_consider_completing_pointee_ty : Note<
68456845
"consider providing a complete definition for %0">;
6846-
6846+
68476847
def note_counted_by_consider_using_sized_by : Note<
68486848
"consider using '__sized_by%select{|_or_null}0' instead of "
68496849
"'__counted_by%select{|_or_null}0'">;
@@ -7745,7 +7745,7 @@ def warn_comparison_of_mixed_enum_types_switch : Warning<
77457745
def warn_arith_conv_mixed__unicode_types
77467746
: Warning<"%sub{select_arith_conv_kind}0 "
77477747
"different Unicode character types %1 and %2">,
7748-
InGroup<ImplicitUnicodeConversion>;
7748+
InGroup<CharacterConversion>;
77497749

77507750
def err_typecheck_assign_const : Error<
77517751
"%select{"

libcxx/test/std/algorithms/alg.nonmodifying/alg.equal/equal.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// We test the cartesian product, so we sometimes compare differently signed types
2222
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
23-
// ADDITIONAL_COMPILE_FLAGS(clang-21): -Wno-implicit-unicode-conversion
23+
// ADDITIONAL_COMPILE_FLAGS(character-conversion-warnings): -Wno-character-conversion
2424

2525
// MSVC warning C4242: 'argument': conversion from 'int' to 'const _Ty', possible loss of data
2626
// MSVC warning C4244: 'argument': conversion from 'wchar_t' to 'const _Ty', possible loss of data

libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// ADDITIONAL_COMPILE_FLAGS(gcc): -Wno-bool-compare
1010
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-sign-compare
11-
// ADDITIONAL_COMPILE_FLAGS(clang-21): -Wno-implicit-unicode-conversion
11+
// ADDITIONAL_COMPILE_FLAGS(character-conversion-warnings): -Wno-character-conversion
1212
// MSVC warning C4245: conversion from 'int' to 'wchar_t', signed/unsigned mismatch
1313
// MSVC warning C4305: truncation from 'int' to 'bool'
1414
// MSVC warning C4310: cast truncates constant value

libcxx/utils/libcxx/test/features.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ def _mingwSupportsModules(cfg):
144144
when=lambda cfg: hasCompileFlag(cfg, "-Wuser-defined-warnings"),
145145
actions=[AddCompileFlag("-Wuser-defined-warnings")],
146146
),
147+
Feature(
148+
name="character-conversion-warnings",
149+
when=lambda cfg: hasCompileFlag(cfg, "-Wcharacter-conversion"),
150+
),
147151
# Tests to validate whether the compiler has a way to set the maximum number
148152
# of steps during constant evaluation. Since the flag differs per compiler
149153
# store the "valid" flag as a feature. This allows passing the proper compile

0 commit comments

Comments
 (0)