[libcxx-commits] [libcxx] 6c6fba8 - Correctly handle using foo = std::foo inside namespaces.

Sterling Augustine via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 26 11:24:34 PDT 2020


Author: Sterling Augustine
Date: 2020-03-26T11:20:09-07:00
New Revision: 6c6fba8808e6e576ee8259b7699e3e4fd545d0bb

URL: https://github.com/llvm/llvm-project/commit/6c6fba8808e6e576ee8259b7699e3e4fd545d0bb
DIFF: https://github.com/llvm/llvm-project/commit/6c6fba8808e6e576ee8259b7699e3e4fd545d0bb.diff

LOG: Correctly handle using foo = std::foo inside namespaces.

Summary:
The gdb pretty printer misprints variables declared via
using declarations of the form:

namespace foo {
using string_view = std::string_view;

string_view bar;
}

This change fixes that, by deferring the decision to ignore
types not inside std until after desugaring.

Reviewers: #libc!

Subscribers: broadwaylamb, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D76816

Added: 
    

Modified: 
    libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
    libcxx/utils/gdb/libcxx/printers.py

Removed: 
    


################################################################################
diff  --git a/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp b/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
index 3050cf15f35a..093fa4f2084e 100644
--- a/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
+++ b/libcxx/test/pretty_printers/gdb_pretty_printer_test.sh.cpp
@@ -153,6 +153,16 @@ void string_test() {
                             "\"mehmet bizim dostumuz agzi kirik testimiz\"");
 }
 
+namespace a_namespace {
+// To test name-lookup in the presence of using inside a namespace. Inside this
+// namespace, unqualified string_view variables will appear in the debug info as
+// "a_namespace::string_view, rather than "std::string_view".
+//
+// There is nothing special here about string_view; it's just the data structure
+// where lookup with using inside a namespace wasn't always working.
+
+using string_view = std::string_view;
+
 void string_view_test() {
   std::string_view i_am_empty;
   ComparePrettyPrintToChars(i_am_empty, "std::string_view of length 0: \"\"");
@@ -166,6 +176,12 @@ void string_view_test() {
   std::string_view wonderful(&char_arr[7], 9);
   ComparePrettyPrintToChars(
       wonderful, "std::string_view of length 9: \"wonderful\"");
+
+  const char char_arr1[] = "namespace_stringview";
+  string_view namespace_stringview(&char_arr1[10], 10);
+  ComparePrettyPrintToChars(
+      namespace_stringview, "std::string_view of length 10: \"stringview\"");
+}
 }
 
 void u16string_test() {
@@ -628,7 +644,7 @@ int main(int argc, char* argv[]) {
   framework_self_test();
 
   string_test();
-  string_view_test();
+  a_namespace::string_view_test();
 
   u32string_test();
   tuple_test();

diff  --git a/libcxx/utils/gdb/libcxx/printers.py b/libcxx/utils/gdb/libcxx/printers.py
index 4b724c94368d..7cccc07997b3 100644
--- a/libcxx/utils/gdb/libcxx/printers.py
+++ b/libcxx/utils/gdb/libcxx/printers.py
@@ -982,10 +982,10 @@ def __call__(self, val):
         # Don't attempt types known to be inside libstdcxx.
         typename = val.type.name or val.type.tag or str(val.type)
         match = re.match("^std::(__.*?)::", typename)
-        if match is None or match.group(1) in ["__cxx1998",
-                                               "__debug",
-                                               "__7",
-                                               "__g"]:
+        if match is not None and match.group(1) in ["__cxx1998",
+                                                    "__debug",
+                                                    "__7",
+                                                    "__g"]:
             return None
 
         # Handle any using declarations or other typedefs.


        


More information about the libcxx-commits mailing list