]> granicus.if.org Git - clang/commitdiff
Don't rely on the default constructor default constructing a begin and
authorChandler Carruth <chandlerc@gmail.com>
Sun, 11 Jan 2015 01:43:06 +0000 (01:43 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 11 Jan 2015 01:43:06 +0000 (01:43 +0000)
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

include/clang/AST/DeclLookups.h
include/clang/AST/DependentDiagnostic.h

index d2016af89f1318c209adfcd96081c7c19195c8eb..eba2266724fd3cfe8a6824268c9725c9343c1eeb 100644 (file)
@@ -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
index 63066797b3a12288cffc71fe38d4bbd834f7615a..8e038c83c9890410bb7ee5f58ee3509e1868c49c 100644 (file)
@@ -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());
 }