[binutils-gdb/gdb-17-branch] gdb/tui: Fix build for older ncurses

Ciaran Woodward via Gdb-cvs <[email protected]> Fri, 31 Jul 2026 11:26:02 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0aa278b805be=
8affc15c4f99dabc6ffaec3da148

commit 0aa278b805be8affc15c4f99dabc6ffaec3da148
Author: Ciaran Woodward <[email protected]>
Date:   Thu Sep 11 16:20:00 2025 +0000

    gdb/tui: Fix build for older ncurses
   =20
    Older versions of ncurses (including the version that ships inside
    macos, and Centos 7) do not include the A_ITALIC macro. This patch
    simply hides any use of A_ITALIC behind a preprocessor guard.
   =20
    The result of this is that italics won't be rendered in the tui
    if ncurses isn't supported. We do have other options if we think
    it's important - for instance we could show italics as bold if
    italics aren't supported. From my understanding, that might be
    overthinking it - so I took the simplest approach here, just to
    fix the build.
   =20
    Those versions also define tgetnum as:
      int tgetnum(char *id);
    so attempting to compile for c++ results in the error:
      ISO C++ forbids converting a string constant to 'char*' [-Werror=3Dwr=
ite-strings]
   =20
    This is just a dated API issue, so a const cast resolves the issue.
   =20
    Approved-By: Tom Tromey <[email protected]>
   =20
    (cherry picked from commit 9076d69190007e263cadbffc480fb93b1ca27f9c)
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/tui/tui-io.c | 4 ++++
 gdb/ui-style.c   | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index c97e8fd1717..84cad9366d5 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -319,7 +319,9 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   wattron (w, A_NORMAL);
   wattroff (w, A_BOLD);
   wattroff (w, A_DIM);
+#ifdef  A_ITALIC
   wattroff (w, A_ITALIC);
+#endif
   wattroff (w, A_UNDERLINE);
   wattroff (w, A_REVERSE);
   if (last_color_pair !=3D -1)
@@ -368,8 +370,10 @@ tui_apply_style (WINDOW *w, ui_file_style style)
       gdb_assert_not_reached ("invalid intensity");
     }
=20
+#ifdef  A_ITALIC
   if (style.is_italic ())
     wattron (w, A_ITALIC);
+#endif
=20
   if (style.is_underline ())
     wattron (w, A_UNDERLINE);
diff --git a/gdb/ui-style.c b/gdb/ui-style.c
index fba4f2835b4..3d142c63dc6 100644
--- a/gdb/ui-style.c
+++ b/gdb/ui-style.c
@@ -594,7 +594,11 @@ colorsupport ()
     {
       std::vector<color_space> result =3D {color_space::MONOCHROME};
=20
-      int colors =3D tgetnum ("Co");
+      /* ncurses versions prior to 6.1 (and other curses
+	 implementations) declare the tgetnum argument to be
+	 'char *', so we need the const_cast, since C++ will not
+	 implicitly convert.  */
+      int colors =3D tgetnum (const_cast<char*> ("Co"));
 #ifdef __MINGW32__
       /* MS-Windows terminal generally doesn't have "Co" in its
 	 terminfo, but always supports at least 8 colors.  */