[cfe-commits] r80302 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/Sema/SemaOverload.cpp test/SemaCXX/overloaded-operator.cpp

Douglas Gregor dgregor at apple.com
Thu Aug 27 16:35:56 PDT 2009


Author: dgregor
Date: Thu Aug 27 18:35:55 2009
New Revision: 80302

URL: http://llvm.org/viewvc/llvm-project?rev=80302&view=rev
Log:
When looking for overloaded member operators, make sure to instantiate
class template specializations (when possible) and look into base
classes. Thanks to Eli for the test case!

FIXME -=1.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/test/SemaCXX/overloaded-operator.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=80302&r1=80301&r2=80302&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 27 18:35:55 2009
@@ -514,7 +514,9 @@
   /// user-declared constructors. When true, a default constructor
   /// will not be implicitly declared.
   bool hasUserDeclaredConstructor() const { 
-    assert(isDefinition() && "Incomplete record decl!");
+    assert((isDefinition() ||
+            cast<RecordType>(getTypeForDecl())->isBeingDefined()) && 
+           "Incomplete record decl!");
     return UserDeclaredConstructor;
   }
 

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=80302&r1=80301&r2=80302&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Aug 27 18:35:55 2009
@@ -2638,11 +2638,17 @@
   //        result of the qualified lookup of T1::operator@
   //        (13.3.1.1.1); otherwise, the set of member candidates is
   //        empty.
-  // FIXME: Lookup in base classes, too!
   if (const RecordType *T1Rec = T1->getAs<RecordType>()) {
-    DeclContext::lookup_const_iterator Oper, OperEnd;
-    for (llvm::tie(Oper, OperEnd) = T1Rec->getDecl()->lookup(OpName);
-         Oper != OperEnd; ++Oper)
+    // Complete the type if it can be completed. Otherwise, we're done.
+    if (RequireCompleteType(OpLoc, T1, PartialDiagnostic(0)))
+      return;
+    
+    LookupResult Operators = LookupQualifiedName(T1Rec->getDecl(), OpName, 
+                                                 LookupOrdinaryName, false);
+    for (LookupResult::iterator Oper = Operators.begin(), 
+                             OperEnd = Operators.end();
+         Oper != OperEnd;
+         ++Oper)
       AddMethodCandidate(cast<CXXMethodDecl>(*Oper), Args[0], 
                          Args+1, NumArgs - 1, CandidateSet,
                          /*SuppressUserConversions=*/false);

Modified: cfe/trunk/test/SemaCXX/overloaded-operator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator.cpp?rev=80302&r1=80301&r2=80302&view=diff

==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-operator.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-operator.cpp Thu Aug 27 18:35:55 2009
@@ -209,3 +209,7 @@
     (void)(x + x);
   }
 }
+
+struct AA { bool operator!=(AA&); };
+struct BB : AA {};
+bool x(BB y, BB z) { return y != z; }





More information about the cfe-commits mailing list