[PATCH] Fix UseAuto not transforming iterators when non-fully qualified names are used and libc++.

Ariel Bernal ariel.j.bernal at intel.com
Tue Jul 9 09:06:21 PDT 2013


Hi Sarcasm, revane, tareqsiraj,

When using libc++ inlining namespaces is used for versioning,  std::_1 is added to the namespace qualifier.
Fixed test based on Guillaume patch.

http://llvm-reviews.chandlerc.com/D1116

Files:
  cpp11-migrate/UseAuto/UseAutoMatchers.cpp
  test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
  test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp

Index: cpp11-migrate/UseAuto/UseAutoMatchers.cpp
===================================================================
--- cpp11-migrate/UseAuto/UseAutoMatchers.cpp
+++ cpp11-migrate/UseAuto/UseAutoMatchers.cpp
@@ -157,6 +157,26 @@
   return false;
 }
 
+/// \brief Matches nested name specifiers that are types and the canonical type
+/// is from the std.
+///
+/// Given
+/// \code
+/// class std::vector<int> p;
+/// class std::_1::vector<int> q;
+/// \endcode
+///
+/// \c elaboratedType(hasQualifier(hasCanonicalTypeFromStd()) matches \c p and
+/// \c q.
+AST_MATCHER(NestedNameSpecifier, hasCanonicalTypeFromStd) {
+  if (const Type *T = Node.getAsType()) {
+    const StringRef R = T->getCanonicalTypeInternal().getAsString();
+    if (R.startswith("class std::"))
+      return true;
+  }
+  return false;
+}
+
 } // namespace ast_matchers
 } // namespace clang
 
@@ -208,9 +228,7 @@
                    )
                  )
                ),
-               hasPrefix(
-                 specifiesNamespace(hasName("std"))
-               )
+               hasCanonicalTypeFromStd()
              )),
              // The named type is what comes after the final
              // '::' in the type. It should name one of the
Index: test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
===================================================================
--- test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
+++ test/cpp11-migrate/UseAuto/Inputs/test_std_container.h
@@ -64,7 +64,7 @@
 namespace std {
 
 #if USE_INLINE_NAMESPACE
-namespace _1 {
+inline namespace _1 {
 #endif
 
 template <typename T>
Index: test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp
===================================================================
--- test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp
+++ test/cpp11-migrate/UseAuto/basic_iterator_tests.cpp
@@ -15,7 +15,7 @@
 //
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \
-// RUN:   -DUSE_INLINE_NAMESPACE -I %S/Inputs
+// RUN:   -DUSE_INLINE_NAMESPACE=1 -I %S/Inputs
 // RUN: FileCheck -input-file=%t.cpp %s
 //
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1116.1.patch
Type: text/x-patch
Size: 2170 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130709/66502104/attachment.bin>


More information about the cfe-commits mailing list