summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
diff options
context:
space:
mode:
authorMatthias Gehre <M.Gehre@gmx.de>2019-09-06 08:56:30 +0000
committerMatthias Gehre <M.Gehre@gmx.de>2019-09-06 08:56:30 +0000
commitf64f4886706b5f50c9feca349edcfae66dce08fa (patch)
tree8af223f03991ef97a89ea7a20d0f1a15c797962a /clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
parent7841e80e79f231d564bf9f849c8e3cad171b7ba4 (diff)
downloadbcm5719-llvm-f64f4886706b5f50c9feca349edcfae66dce08fa.tar.gz
bcm5719-llvm-f64f4886706b5f50c9feca349edcfae66dce08fa.zip
Reland [LifetimeAnalysis] Support more STL idioms (template forward declaration and DependentNameType)
Reland after https://reviews.llvm.org/D66806 fixed the false-positive diagnostics. Summary: This fixes inference of gsl::Pointer on std::set::iterator with libstdc++ (the typedef for iterator on the template is a DependentNameType - we can only put the gsl::Pointer attribute on the underlaying record after instantiation) inference of gsl::Pointer on std::vector::iterator with libc++ (the class was forward-declared, we added the gsl::Pointer on the canonical decl (the forward decl), and later when the template was instantiated, there was no attribute on the definition so it was not instantiated). and a duplicate gsl::Pointer on some class with libstdc++ (we first added an attribute to a incomplete instantiation, and then another was copied from the template definition when the instantiation was completed). We now add the attributes to all redeclarations to fix thos issues and make their usage easier. Reviewers: gribozavr Subscribers: Szelethus, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66179 llvm-svn: 371182
Diffstat (limited to 'clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp')
-rw-r--r--clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp b/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
index 29675c2ac7e..352e1e47358 100644
--- a/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
+++ b/clang/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
@@ -92,6 +92,59 @@ public:
static_assert(sizeof(unordered_map<int>::iterator), ""); // Force instantiation.
} // namespace inlinens
+// The iterator typedef is a DependentNameType.
+template <typename T>
+class __unordered_multimap_iterator {};
+// CHECK: ClassTemplateDecl {{.*}} __unordered_multimap_iterator
+// CHECK: ClassTemplateSpecializationDecl {{.*}} __unordered_multimap_iterator
+// CHECK: TemplateArgument type 'int'
+// CHECK: PointerAttr
+
+template <typename T>
+class __unordered_multimap_base {
+public:
+ using iterator = __unordered_multimap_iterator<T>;
+};
+
+template <typename T>
+class unordered_multimap {
+ // CHECK: ClassTemplateDecl {{.*}} unordered_multimap
+ // CHECK: OwnerAttr {{.*}}
+ // CHECK: ClassTemplateSpecializationDecl {{.*}} unordered_multimap
+ // CHECK: OwnerAttr {{.*}}
+public:
+ using _Mybase = __unordered_multimap_base<T>;
+ using iterator = typename _Mybase::iterator;
+};
+static_assert(sizeof(unordered_multimap<int>::iterator), ""); // Force instantiation.
+
+// The canonical declaration of the iterator template is not its definition.
+template <typename T>
+class __unordered_multiset_iterator;
+// CHECK: ClassTemplateDecl {{.*}} __unordered_multiset_iterator
+// CHECK: PointerAttr
+// CHECK: ClassTemplateSpecializationDecl {{.*}} __unordered_multiset_iterator
+// CHECK: TemplateArgument type 'int'
+// CHECK: PointerAttr
+
+template <typename T>
+class __unordered_multiset_iterator {
+ // CHECK: ClassTemplateDecl {{.*}} prev {{.*}} __unordered_multiset_iterator
+ // CHECK: PointerAttr
+};
+
+template <typename T>
+class unordered_multiset {
+ // CHECK: ClassTemplateDecl {{.*}} unordered_multiset
+ // CHECK: OwnerAttr {{.*}}
+ // CHECK: ClassTemplateSpecializationDecl {{.*}} unordered_multiset
+ // CHECK: OwnerAttr {{.*}}
+public:
+ using iterator = __unordered_multiset_iterator<T>;
+};
+
+static_assert(sizeof(unordered_multiset<int>::iterator), ""); // Force instantiation.
+
// std::list has an implicit gsl::Owner attribute,
// but explicit attributes take precedence.
template <typename T>
OpenPOWER on IntegriCloud