summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-01-11 01:43:06 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-01-11 01:43:06 +0000
commit04957ceb0bd158b25aa536d293e798928a9fa846 (patch)
treefb09f4817773ba5ac3214cf9c5d689f621c4b08e
parent0c50e1a203c66774d91742b69654576bb65defd6 (diff)
Don't rely on the default constructor default constructing a begin and
end iterator for iterator_range<>. I removed this constructor because for some iterators (notably pointers) it left begin and end uninitialized. It also is an usual constraint that an iterator default constructs to a valid end iterator such that the pair of them for a valid range. In the three places where this was used in Clang, explicitly build the empty range from the iterators and comment on why default constructed iterators make sense here. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225594 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclLookups.h10
-rw-r--r--include/clang/AST/DependentDiagnostic.h3
2 files changed, 10 insertions, 3 deletions
diff --git a/include/clang/AST/DeclLookups.h b/include/clang/AST/DeclLookups.h
index d2016af89f..eba2266724 100644
--- a/include/clang/AST/DeclLookups.h
+++ b/include/clang/AST/DeclLookups.h
@@ -75,7 +75,10 @@ inline DeclContext::lookups_range DeclContext::lookups() const {
if (StoredDeclsMap *Map = Primary->buildLookup())
return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
all_lookups_iterator(Map->end(), Map->end()));
- return lookups_range();
+
+ // Synthesize an empty range. This requires that two default constructed
+ // versions of these iterators form a valid empty range.
+ return lookups_range(all_lookups_iterator(), all_lookups_iterator());
}
inline DeclContext::all_lookups_iterator DeclContext::lookups_begin() const {
@@ -91,7 +94,10 @@ inline DeclContext::lookups_range DeclContext::noload_lookups() const {
if (StoredDeclsMap *Map = Primary->getLookupPtr())
return lookups_range(all_lookups_iterator(Map->begin(), Map->end()),
all_lookups_iterator(Map->end(), Map->end()));
- return lookups_range();
+
+ // Synthesize an empty range. This requires that two default constructed
+ // versions of these iterators form a valid empty range.
+ return lookups_range(all_lookups_iterator(), all_lookups_iterator());
}
inline
diff --git a/include/clang/AST/DependentDiagnostic.h b/include/clang/AST/DependentDiagnostic.h
index 63066797b3..8e038c83c9 100644
--- a/include/clang/AST/DependentDiagnostic.h
+++ b/include/clang/AST/DependentDiagnostic.h
@@ -178,7 +178,8 @@ inline DeclContext::ddiag_range DeclContext::ddiags() const {
= static_cast<DependentStoredDeclsMap*>(getPrimaryContext()->getLookupPtr());
if (!Map)
- return ddiag_range();
+ // Return an empty range using the always-end default constructor.
+ return ddiag_range(ddiag_iterator(), ddiag_iterator());
return ddiag_range(ddiag_iterator(Map->FirstDiagnostic), ddiag_iterator());
}