Fix a crasher involving template instantiation of non-dependent
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
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index b6072d8..206193b 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -752,8 +752,10 @@
   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();
+    }
   }
 }
 
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index f1888c8..e7400e7 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -4525,16 +4525,12 @@
   // 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.
diff --git a/test/SemaTemplate/instantiate-expr-2.cpp b/test/SemaTemplate/instantiate-expr-2.cpp
index 2c3ccb0..5351701 100644
--- a/test/SemaTemplate/instantiate-expr-2.cpp
+++ b/test/SemaTemplate/instantiate-expr-2.cpp
@@ -146,3 +146,17 @@
     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>;  
+}