]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
diagnostics: special-case -fdiagnostics-text-art-charset=ascii for LANG=C
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 16 Oct 2023 23:04:50 +0000 (19:04 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 16 Oct 2023 23:04:50 +0000 (19:04 -0400)
In the LWN discussion of the "ASCII" art in GCC 14
  https://lwn.net/Articles/946733/#Comments
there was some concern about the use of non-ASCII characters in the
output.

Currently -fdiagnostics-text-art-charset defaults to "emoji".
To better handle older terminals by default, this patch special-cases
LANG=C to use -fdiagnostics-text-art-charset=ascii.

gcc/ChangeLog:
* diagnostic.cc (diagnostic_initialize): When LANG=C, update
default for -fdiagnostics-text-art-charset from emoji to ascii.
* doc/invoke.texi (fdiagnostics-text-art-charset): Document the above.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/diagnostic.cc
gcc/doc/invoke.texi

index 03637459c56c3601f03d02310dea043ed230c83b..6e46371b3b4e78e91a2bd9694c8d04327d7536bc 100644 (file)
@@ -226,8 +226,17 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
   context->includes_seen = NULL;
   context->m_client_data_hooks = NULL;
   context->m_diagrams.m_theme = NULL;
-  diagnostics_text_art_charset_init (context,
-                                    DIAGNOSTICS_TEXT_ART_CHARSET_DEFAULT);
+
+  enum diagnostic_text_art_charset text_art_charset
+    = DIAGNOSTICS_TEXT_ART_CHARSET_DEFAULT;
+  if (const char *lang = getenv ("LANG"))
+    {
+      /* For LANG=C, don't assume the terminal supports anything
+        other than ASCII.  */
+      if (!strcmp (lang, "C"))
+       text_art_charset = DIAGNOSTICS_TEXT_ART_CHARSET_ASCII;
+    }
+  diagnostics_text_art_charset_init (context, text_art_charset);
 }
 
 /* Maybe initialize the color support. We require clients to do this
index 2a500c1baeea25003eaf8be4d2dde6716f9aba2a..db59d8b6d4af3a8f1e094f4e736a09900269b234 100644 (file)
@@ -5688,7 +5688,8 @@ value further adds the possibility of emoji in the output (such as emitting
 U+26A0 WARNING SIGN followed by U+FE0F VARIATION SELECTOR-16 to select the
 emoji variant of the character).
 
-The default is @samp{emoji}.
+The default is @samp{emoji}, except when the environment variable @env{LANG}
+is set to @samp{C}, in which case the default is @samp{ascii}.
 
 @opindex fdiagnostics-format
 @item -fdiagnostics-format=@var{FORMAT}