Recommit r102215, this time being more careful to only set the "principal
declaration" (i.e. the only which will actually be looked up) to have the
non-member-operator bit.

llvm-svn: 102231
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3964b75..cdfd055 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3255,20 +3255,25 @@
           Previous.getResultKind() != LookupResult::FoundOverloaded) &&
          "previous declaration set still overloaded");
 
+  NamedDecl *PrincipalDecl = (FunctionTemplate
+                              ? cast<NamedDecl>(FunctionTemplate)
+                              : NewFD);
+
   if (isFriend && Redeclaration) {
     AccessSpecifier Access = AS_public;
     if (!NewFD->isInvalidDecl())
       Access = NewFD->getPreviousDeclaration()->getAccess();
 
-    if (FunctionTemplate) {
-      FunctionTemplate->setObjectOfFriendDecl(true);
-      FunctionTemplate->setAccess(Access);
-    } else {
-      NewFD->setObjectOfFriendDecl(true);
-    }
     NewFD->setAccess(Access);
+    if (FunctionTemplate) FunctionTemplate->setAccess(Access);
+
+    PrincipalDecl->setObjectOfFriendDecl(true);
   }
 
+  if (NewFD->isOverloadedOperator() && !DC->isRecord() &&
+      PrincipalDecl->isInIdentifierNamespace(Decl::IDNS_Ordinary))
+    PrincipalDecl->setNonMemberOperator();
+
   // If we have a function template, check the template parameter
   // list. This will check and merge default template arguments.
   if (FunctionTemplate) {