[PATCH] Fix UseAuto not transforming iterators when non-fully qualified names are used and libc++.
Ariel Bernal
ariel.j.bernal at intel.com
Wed Jul 10 09:57:45 PDT 2013
Address review comments
Hi Sarcasm, revane, tareqsiraj,
http://llvm-reviews.chandlerc.com/D1116
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1116?vs=2731&id=2754#toc
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
@@ -100,7 +100,6 @@
"const_iterator",
"const_reverse_iterator"
};
-
for (unsigned int i = 0;
i < llvm::array_lengthof(IteratorNames);
++i) {
@@ -122,7 +121,7 @@
///
/// \c recordDecl(hasStdContainerName()) matches \c vector and \c forward_list
/// but not \c my_vec.
-AST_MATCHER_P(NamedDecl, hasStdContainerName, bool, WithStd) {
+AST_MATCHER(NamedDecl, hasStdContainerName) {
static const char *ContainerNames[] = {
"array",
"deque",
@@ -148,15 +147,42 @@
for (unsigned int i = 0;
i < llvm::array_lengthof(ContainerNames);
++i) {
- std::string Name(ContainerNames[i]);
- if (WithStd)
- Name = "std::" + Name;
- if (hasName(Name).matches(Node, Finder, Builder))
+ if (hasName(ContainerNames[i]).matches(Node, Finder, Builder))
return true;
}
return false;
}
+/// \brief Matches declarations whose declaration context is the C++ standard
+/// library namespace \c std.
+///
+/// Note that inline namespaces are silently ignored during the lookup since
+/// both libstdc++ and libc++ are known to use them for versioning purposes.
+///
+/// Given
+/// \code
+/// namespace ns {
+/// struct my_type {};
+/// using namespace std;
+/// }
+///
+/// using std::vector;
+/// using ns::my_type;
+/// using ns::list;
+/// \endcode
+/// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(isFromStdNamespace())))
+/// matches "using std::vector" and "using ns::list".
+AST_MATCHER(Decl, isFromStdNamespace) {
+ const DeclContext *D = Node.getDeclContext();
+ while (D->isInlineNamespace())
+ D = D->getParent();
+ if (!D->isNamespace() || !D->getParent()->isTranslationUnit())
+ return false;
+
+ const IdentifierInfo *Info = cast<NamespaceDecl>(D)->getIdentifier();
+ return Info && Info->isStr("std");
+}
+
} // namespace ast_matchers
} // namespace clang
@@ -169,7 +195,7 @@
allOf(
namedDecl(hasStdIteratorName()),
hasDeclContext(
- recordDecl(hasStdContainerName(true))
+ recordDecl(hasStdContainerName(), isFromStdNamespace())
)
)
)
@@ -184,7 +210,7 @@
allOf(
namedDecl(hasStdIteratorName()),
hasDeclContext(
- recordDecl(hasStdContainerName(true))
+ recordDecl(hasStdContainerName(), isFromStdNamespace())
)
)
)
@@ -204,7 +230,7 @@
specifiesType(
templateSpecializationType(
hasDeclaration(
- namedDecl(hasStdContainerName(false))
+ namedDecl(hasStdContainerName(), isFromStdNamespace())
)
)
),
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>
@@ -114,7 +114,6 @@
#if USE_INLINE_NAMESPACE
} // namespace _1
-using _1::CONTAINER;
#endif
} // namespace std
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,17 +15,17 @@
//
// 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
// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \
-// RUN: -DUSE_BASE_CLASS_ITERATORS -I %S/Inputs
+// RUN: -DUSE_BASE_CLASS_ITERATORS=1 -I %S/Inputs
// RUN: FileCheck -input-file=%t.cpp %s
//
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: cpp11-migrate -use-auto %t.cpp -- -DCONTAINER=array \
-// RUN: -DUSE_INNER_CLASS_ITERATORS -I %S/Inputs
+// RUN: -DUSE_INNER_CLASS_ITERATORS=1 -I %S/Inputs
// RUN: FileCheck -input-file=%t.cpp %s
//
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1116.2.patch
Type: text/x-patch
Size: 4551 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130710/7f8d5137/attachment.bin>
More information about the cfe-commits
mailing list