r225594 - Don't rely on the default constructor default constructing a begin and

Chandler Carruth chandlerc at gmail.com
Sat Jan 10 17:43:06 PST 2015


Author: chandlerc
Date: Sat Jan 10 19:43:06 2015
New Revision: 225594

URL: http://llvm.org/viewvc/llvm-project?rev=225594&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/AST/DeclLookups.h
    cfe/trunk/include/clang/AST/DependentDiagnostic.h

Modified: cfe/trunk/include/clang/AST/DeclLookups.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclLookups.h?rev=225594&r1=225593&r2=225594&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclLookups.h (original)
+++ cfe/trunk/include/clang/AST/DeclLookups.h Sat Jan 10 19:43:06 2015
@@ -75,7 +75,10 @@ inline DeclContext::lookups_range DeclCo
   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 DeclCo
   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

Modified: cfe/trunk/include/clang/AST/DependentDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DependentDiagnostic.h?rev=225594&r1=225593&r2=225594&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DependentDiagnostic.h (original)
+++ cfe/trunk/include/clang/AST/DependentDiagnostic.h Sat Jan 10 19:43:06 2015
@@ -178,7 +178,8 @@ inline DeclContext::ddiag_range DeclCont
     = 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());
 }





More information about the cfe-commits mailing list