]> granicus.if.org Git - clang/commitdiff
Fix a crasher involving template instantiation of non-dependent
authorDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 16:58:52 +0000 (16:58 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 1 Sep 2009 16:58:52 +0000 (16:58 +0000)
expressions making use of an overloaded operator. Thanks for the test
case, Anders!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80679 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclCXX.cpp
lib/Sema/TreeTransform.h
test/SemaTemplate/instantiate-expr-2.cpp

index b6072d8acd5ba87485dbf4124a006574e29dddb7..206193ba8125811c38a003b16fd82a4d6b402d67 100644 (file)
@@ -752,8 +752,10 @@ OverloadIterator::OverloadIterator(NamedDecl *ND) : D(0) {
   if (isa<FunctionDecl>(ND) || isa<FunctionTemplateDecl>(ND))
     D = ND;
   else if (OverloadedFunctionDecl *Ovl = dyn_cast<OverloadedFunctionDecl>(ND)) {
-    D = ND;
-    Iter = Ovl->function_begin();
+    if (Ovl->size() != 0) {
+      D = ND;
+      Iter = Ovl->function_begin();
+    }
   }
 }
 
index f1888c87a43f073c1a06ec1a99e171e1a92b5cac..e7400e74734a4c582b77272ac91ba82139a297df 100644 (file)
@@ -4525,16 +4525,12 @@ TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
   // used during overload resolution.
   Sema::FunctionSet Functions;
   
-  DeclRefExpr *DRE = cast<DeclRefExpr>((Expr *)Callee.get());
-  OverloadedFunctionDecl *Overloads 
-    = cast<OverloadedFunctionDecl>(DRE->getDecl());
+  DeclRefExpr *DRE 
+    = cast<DeclRefExpr>(((Expr *)Callee.get())->IgnoreParenCasts());
   
   // FIXME: Do we have to check
   // IsAcceptableNonMemberOperatorCandidate for each of these?
-  for (OverloadedFunctionDecl::function_iterator 
-       F = Overloads->function_begin(),
-       FEnd = Overloads->function_end();
-       F != FEnd; ++F)
+  for (OverloadIterator F(DRE->getDecl()), FEnd; F != FEnd; ++F)
     Functions.insert(*F);
   
   // Add any functions found via argument-dependent lookup.
index 2c3ccb06e4205b7271a812da8cd899a00cf9438a..5351701cdcdc2da2958c9521844341b2e72c0201 100644 (file)
@@ -146,3 +146,17 @@ namespace N8 {
     test_plus(&x, x, x);
   }
 }
+
+namespace N9 {
+  struct A {
+    bool operator==(int value);
+  };
+  
+  template<typename T> struct B {
+    bool f(A a) {
+      return a == 1;
+    }
+  };
+  
+  template struct B<int>;  
+}