;
Wbidi-chars=
-C ObjC C++ ObjC++ RejectNegative Joined Warning CPP(cpp_warn_bidirectional) CppReason(CPP_W_BIDIRECTIONAL) Var(warn_bidirectional) Init(bidirectional_unpaired) Enum(cpp_bidirectional_level)
--Wbidi-chars=[none|unpaired|any] Warn about UTF-8 bidirectional control characters.
+C ObjC C++ ObjC++ RejectNegative Joined Warning CPP(cpp_warn_bidirectional) CppReason(CPP_W_BIDIRECTIONAL) Var(warn_bidirectional) Init(bidirectional_unpaired) Enum(cpp_bidirectional_level) EnumSet
+-Wbidi-chars=[none|unpaired|any|ucn] Warn about UTF-8 bidirectional control characters.
; Required for these enum values.
SourceInclude
Name(cpp_bidirectional_level) Type(int) UnknownError(argument %qs to %<-Wbidi-chars%> not recognized)
EnumValue
-Enum(cpp_bidirectional_level) String(none) Value(bidirectional_none)
+Enum(cpp_bidirectional_level) String(none) Value(bidirectional_none) Set(1)
EnumValue
-Enum(cpp_bidirectional_level) String(unpaired) Value(bidirectional_unpaired)
+Enum(cpp_bidirectional_level) String(unpaired) Value(bidirectional_unpaired) Set(1)
EnumValue
-Enum(cpp_bidirectional_level) String(any) Value(bidirectional_any)
+Enum(cpp_bidirectional_level) String(any) Value(bidirectional_any) Set(1)
+
+EnumValue
+Enum(cpp_bidirectional_level) String(ucn) Value(bidirectional_ucn) Set(2)
Wbool-compare
C ObjC C++ ObjC++ Var(warn_bool_compare) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall)
-Warray-bounds -Warray-bounds=@var{n} -Warray-compare @gol
-Wno-attributes -Wattribute-alias=@var{n} -Wno-attribute-alias @gol
-Wno-attribute-warning @gol
--Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{]} @gol
+-Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{|}ucn@r{]} @gol
-Wbool-compare -Wbool-operation @gol
-Wno-builtin-declaration-mismatch @gol
-Wno-builtin-macro-redefined -Wc90-c99-compat -Wc99-c11-compat @gol
This is the default. You can disable these warnings with either
@option{-Wno-attribute-alias} or @option{-Wattribute-alias=0}.
-@item -Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{]}
+@item -Wbidi-chars=@r{[}none@r{|}unpaired@r{|}any@r{|}ucn@r{]}
@opindex Wbidi-chars=
@opindex Wbidi-chars
@opindex Wno-bidi-chars
@option{-Wbidi-chars=any} warns about any use of bidirectional control
characters.
+By default, this warning does not warn about UCNs. It is, however, possible
+to turn on such checking by using @option{-Wbidi-chars=unpaired,ucn} or
+@option{-Wbidi-chars=any,ucn}.
+
@item -Wbool-compare
@opindex Wno-bool-compare
@opindex Wbool-compare
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
/* More nesting testing. */
/* RLE LRI PDF PDI*/
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
/* Test that we warn when mixing UCN and UTF-8. */
int LRE__PDF_\u202c;
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
/* Test PDI handling, which also pops any subsequent LREs, RLEs, LROs,
or RLOs. */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=any" } */
+/* { dg-options "-Wbidi-chars=any,ucn" } */
/* Test LTR/RTL chars. */
/* LTR<> */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
/* Test LTR/RTL chars. */
/* LTR<> */
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* By default, don't warn about UCNs. */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-bogus "unpaired" "" { target *-*-* } .-1 } */
+ return aText;
+}
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-warning "unpaired" "" { target *-*-* } .-1 } */
+ return aText;
+}
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* { dg-options "-Wbidi-chars=any" } */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-bogus "U\\+202D" "" { target *-*-* } .-1 } */
+ return aText;
+}
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* { dg-options "-Wbidi-chars=ucn,any" } */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-warning "U\\+202D" "" { target *-*-* } .-1 } */
+ return aText;
+}
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* { dg-options "-Wbidi-chars=none,ucn" } */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-bogus "" "" { target *-*-* } .-1 } */
+ return aText;
+}
--- /dev/null
+/* PR preprocessor/104030 */
+/* { dg-do compile } */
+/* { dg-options "-Wbidi-chars=ucn" } */
+
+const char *
+fn ()
+{
+ const char *aText = "\u202D" "abc";
+/* { dg-warning "unpaired" "" { target *-*-* } .-1 } */
+ return aText;
+}
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=any -Wno-multichar -Wno-overflow" } */
+/* { dg-options "-Wbidi-chars=any,ucn -Wno-multichar -Wno-overflow" } */
/* Test all bidi chars in various contexts (identifiers, comments,
string literals, character constants), both UCN and UTF-8. The bidi
chars here are properly terminated, except for the character constants. */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired -Wno-multichar -Wno-overflow" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn -Wno-multichar -Wno-overflow" } */
/* Test all bidi chars in various contexts (identifiers, comments,
string literals, character constants), both UCN and UTF-8. The bidi
chars here are properly terminated, except for the character constants. */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=ucn,unpaired" } */
/* Test nesting of bidi chars in various contexts. */
/* Terminated by the wrong char: */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=any" } */
+/* { dg-options "-Wbidi-chars=any,ucn" } */
/* Test we ignore UCNs in comments. */
// a b c \u202a 1 2 3
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=any" } */
+/* { dg-options "-Wbidi-chars=any,ucn" } */
/* Test \u vs \U. */
int a_\u202A;
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn" } */
/* Test that we properly separate bidi contexts (comment/identifier/character
constant/string literal). */
/* PR preprocessor/103026 */
/* { dg-do compile } */
-/* { dg-options "-Wbidi-chars=unpaired -fdiagnostics-show-caret" } */
+/* { dg-options "-Wbidi-chars=unpaired,ucn -fdiagnostics-show-caret" } */
/* Verify that we escape and underline pertinent bidirectional
control characters when quoting the source. */
CMS_system, /* Search the system INCLUDE path. */
};
-/* The possible bidirectional control characters checking levels, from least
- restrictive to most. */
+/* The possible bidirectional control characters checking levels. */
enum cpp_bidirectional_level {
/* No checking. */
- bidirectional_none,
+ bidirectional_none = 0,
/* Only detect unpaired uses of bidirectional control characters. */
- bidirectional_unpaired,
+ bidirectional_unpaired = 1,
/* Detect any use of bidirectional control characters. */
- bidirectional_any
+ bidirectional_any = 2,
+ /* Also warn about UCNs. */
+ bidirectional_ucn = 4
};
/* This structure is nested inside struct cpp_reader, and
characters. */
bool warn_bidi_p () const
{
- return CPP_OPTION (this, cpp_warn_bidirectional) != bidirectional_none;
+ return (CPP_OPTION (this, cpp_warn_bidirectional)
+ & (bidirectional_unpaired|bidirectional_any));
}
};
static void
maybe_warn_bidi_on_close (cpp_reader *pfile, const uchar *p)
{
- if (CPP_OPTION (pfile, cpp_warn_bidirectional) == bidirectional_unpaired
- && bidi::vec.count () > 0)
+ const auto warn_bidi = CPP_OPTION (pfile, cpp_warn_bidirectional);
+ if (bidi::vec.count () > 0
+ && (warn_bidi & bidirectional_unpaired
+ && (!bidi::current_ctx_ucn_p ()
+ || (warn_bidi & bidirectional_ucn))))
{
const location_t loc
= linemap_position_for_column (pfile->line_table,
const auto warn_bidi = CPP_OPTION (pfile, cpp_warn_bidirectional);
- if (warn_bidi != bidirectional_none)
+ if (warn_bidi & (bidirectional_unpaired|bidirectional_any))
{
rich_location rich_loc (pfile->line_table, loc);
rich_loc.set_escape_on_output (true);
/* It seems excessive to warn about a PDI/PDF that is closing
an opened context because we've already warned about the
opening character. Except warn when we have a UCN x UTF-8
- mismatch. */
+ mismatch, if UCN checking is enabled. */
if (kind == bidi::current_ctx ())
{
- if (warn_bidi == bidirectional_unpaired
+ if (warn_bidi == (bidirectional_unpaired|bidirectional_ucn)
&& bidi::current_ctx_ucn_p () != ucn_p)
{
rich_loc.add_range (bidi::current_ctx_loc ());
"a context by \"%s\"", bidi::to_str (kind));
}
}
- else if (warn_bidi == bidirectional_any)
+ else if (warn_bidi & bidirectional_any
+ && (!ucn_p || (warn_bidi & bidirectional_ucn)))
{
if (kind == bidi::kind::PDF || kind == bidi::kind::PDI)
cpp_warning_at (pfile, CPP_W_BIDIRECTIONAL, &rich_loc,