Quellcode durchsuchen

Remove ref/value inconsistency in redecl_iterator.

Similar to r155808 - this mistake has been made in a few iterators.

Based on Chandler Carruth's feedback to r155808 I added an implicit conversion
to Decl* to ease adoption/usage. Useful for the pointer comparison, but not the
dyn_cast (due to template argument deduction causing the conversion not to be
used) - there for future convenience, though. This idiom (op T* for iterators)
seems to be fairly idiomatic within the LLVM codebase & I'll likely add it as I
fix up the other iterators here.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155869 91177308-0d34-0410-b5e6-96231b3b80d8
David Blaikie vor 13 Jahren
Ursprung
Commit
bd4fa45e7c

+ 6 - 5
include/clang/AST/DeclBase.h

@@ -692,17 +692,18 @@ public:
     Decl *Starter;
     Decl *Starter;
 
 
   public:
   public:
-    typedef Decl*                     value_type;
-    typedef Decl*                     reference;
-    typedef Decl*                     pointer;
+    typedef Decl                     value_type;
+    typedef value_type&              reference;
+    typedef value_type*              pointer;
     typedef std::forward_iterator_tag iterator_category;
     typedef std::forward_iterator_tag iterator_category;
     typedef std::ptrdiff_t            difference_type;
     typedef std::ptrdiff_t            difference_type;
 
 
     redecl_iterator() : Current(0) { }
     redecl_iterator() : Current(0) { }
     explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
     explicit redecl_iterator(Decl *C) : Current(C), Starter(C) { }
 
 
-    reference operator*() const { return Current; }
+    reference operator*() const { return *Current; }
     pointer operator->() const { return Current; }
     pointer operator->() const { return Current; }
+    operator pointer() const { return Current; }
 
 
     redecl_iterator& operator++() {
     redecl_iterator& operator++() {
       assert(Current && "Advancing while iterator has reached end");
       assert(Current && "Advancing while iterator has reached end");
@@ -1320,7 +1321,7 @@ public:
 
 
     filtered_decl_iterator() : Current() { }
     filtered_decl_iterator() : Current() { }
 
 
-    /// specific_decl_iterator - Construct a new iterator over a
+    /// filtered_decl_iterator - Construct a new iterator over a
     /// subset of the declarations the range [C,
     /// subset of the declarations the range [C,
     /// end-of-declarations). If A is non-NULL, it is a pointer to a
     /// end-of-declarations). If A is non-NULL, it is a pointer to a
     /// member function of SpecificDecl that should return true for
     /// member function of SpecificDecl that should return true for

+ 1 - 1
lib/ARCMigrate/TransGCAttrs.cpp

@@ -166,7 +166,7 @@ public:
 
 
     for (Decl::redecl_iterator
     for (Decl::redecl_iterator
            I = D->redecls_begin(), E = D->redecls_end(); I != E; ++I)
            I = D->redecls_begin(), E = D->redecls_end(); I != E; ++I)
-      if (!isInMainFile((*I)->getLocation()))
+      if (!isInMainFile(I->getLocation()))
         return false;
         return false;
     
     
     return true;
     return true;

+ 1 - 1
lib/Sema/IdentifierResolver.cpp

@@ -304,7 +304,7 @@ static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) {
     for (Decl::redecl_iterator RD = New->redecls_begin(), 
     for (Decl::redecl_iterator RD = New->redecls_begin(), 
                             RDEnd = New->redecls_end();
                             RDEnd = New->redecls_end();
          RD != RDEnd; ++RD) {
          RD != RDEnd; ++RD) {
-      if (*RD == Existing)
+      if (RD == Existing)
         return DMK_Replace;
         return DMK_Replace;
         
         
       if (RD->isCanonicalDecl())
       if (RD->isCanonicalDecl())

+ 1 - 1
lib/Sema/SemaLookup.cpp

@@ -1069,7 +1069,7 @@ static NamedDecl *getVisibleDecl(NamedDecl *D) {
   
   
   for (Decl::redecl_iterator RD = D->redecls_begin(), RDEnd = D->redecls_end();
   for (Decl::redecl_iterator RD = D->redecls_begin(), RDEnd = D->redecls_end();
        RD != RDEnd; ++RD) {
        RD != RDEnd; ++RD) {
-    if (NamedDecl *ND = dyn_cast<NamedDecl>(*RD)) {
+    if (NamedDecl *ND = dyn_cast<NamedDecl>(&*RD)) {
       if (LookupResult::isVisible(ND))
       if (LookupResult::isVisible(ND))
         return ND;
         return ND;
     }
     }