]> gcc.gnu.org Git - gcc.git/commitdiff
libstdc++: Add GDB printer for std::integral_constant
authorJonathan Wakely <jwakely@redhat.com>
Wed, 10 Jan 2024 10:53:43 +0000 (10:53 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 11 Jan 2024 17:35:57 +0000 (17:35 +0000)
libstdc++-v3/ChangeLog:

* python/libstdcxx/v6/printers.py (StdIntegralConstantPrinter):
Add printer for std::integral_constant.
* testsuite/libstdc++-prettyprinters/cxx11.cc: Test it.

libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/testsuite/libstdc++-prettyprinters/cxx11.cc

index bf0dc52ab8c94405fdff3c25fdaa510fabaa1a1a..032a7aa58a24c1d7534d8a509a3caec160a17d0a 100644 (file)
@@ -2306,6 +2306,23 @@ class StdLocalePrinter(printer_base):
                     mod = ' with "{}={}"'.format(cat, other)
         return 'std::locale = "{}"{}'.format(name, mod)
 
+class StdIntegralConstantPrinter(printer_base):
+    """Print a std::true_type or std::false_type."""
+
+    def __init__(self, typename, val):
+        self._val = val
+        self._typename = typename
+
+    def to_string(self):
+        value_type = self._val.type.template_argument(0)
+        value = self._val.type.template_argument(1)
+        if value_type.code == gdb.TYPE_CODE_BOOL:
+            if value:
+                return "std::true_type"
+            else:
+                return "std::false_type"
+        typename = strip_versioned_namespace(self._typename)
+        return "{}<{}, {}>".format(typename, value_type, value)
 
 # A "regular expression" printer which conforms to the
 # "SubPrettyPrinter" protocol from gdb.printing.
@@ -2788,6 +2805,9 @@ def build_libstdcxx_dictionary():
     # vector<bool>
     libstdcxx_printer.add_version('std::', 'locale', StdLocalePrinter)
 
+    libstdcxx_printer.add_version('std::', 'integral_constant',
+                                  StdIntegralConstantPrinter)
+
     if hasattr(gdb.Value, 'dynamic_type'):
         libstdcxx_printer.add_version('std::', 'error_code',
                                       StdErrorCodePrinter)
index bc869fd412240f8c09f11831503a58151e6748aa..f867ea18306d5f6f5c5ea1100c4b8a55aeb44fe1 100644 (file)
@@ -207,6 +207,13 @@ main()
   std::atomic<Value> av{{8, 9}};
   // { dg-final { note-test av {std::atomic<Value> = { {i = 8, j = 9} }} } }
 
+  std::integral_constant<int, 1> one;
+  // { dg-final { note-test one {std::integral_constant<int, 1>} } }
+  std::integral_constant<bool, true> truth;
+  // { dg-final { note-test truth {std::true_type} } }
+  std::integral_constant<bool, 0> lies;
+  // { dg-final { note-test lies {std::false_type} } }
+
   placeholder(""); // Mark SPOT
   use(efl);
   use(fl);
This page took 0.071068 seconds and 5 git commands to generate.