[cfe-commits] r84963 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaLookup.cpp lib/Sema/SemaOverload.cpp lib/Sema/TreeTransform.h test/SemaCXX/overloaded-operator.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Fri Oct 23 12:23:15 PDT 2009


Author: cornedbee
Date: Fri Oct 23 14:23:15 2009
New Revision: 84963

URL: http://llvm.org/viewvc/llvm-project?rev=84963&view=rev
Log:
Apply the special enum restrictions from [over.match.oper]p3b2 in argument-dependent lookup too. This fixes PR5244.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp
    cfe/trunk/lib/Sema/TreeTransform.h
    cfe/trunk/test/SemaCXX/overloaded-operator.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=84963&r1=84962&r2=84963&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Oct 23 14:23:15 2009
@@ -1377,7 +1377,7 @@
                                     QualType T1, QualType T2,
                                     FunctionSet &Functions);
 
-  void ArgumentDependentLookup(DeclarationName Name,
+  void ArgumentDependentLookup(DeclarationName Name, bool Operator,
                                Expr **Args, unsigned NumArgs,
                                FunctionSet &Functions);
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Oct 23 14:23:15 2009
@@ -5435,7 +5435,7 @@
       Expr *Args[2] = { lhs, rhs };
       DeclarationName OpName
         = Context.DeclarationNames.getCXXOperatorName(OverOp);
-      ArgumentDependentLookup(OpName, Args, 2, Functions);
+      ArgumentDependentLookup(OpName, /*Operator*/true, Args, 2, Functions);
     }
 
     // Build the (potentially-overloaded, potentially-dependent)
@@ -5553,7 +5553,7 @@
                                    Functions);
       DeclarationName OpName
         = Context.DeclarationNames.getCXXOperatorName(OverOp);
-      ArgumentDependentLookup(OpName, &Input, 1, Functions);
+      ArgumentDependentLookup(OpName, /*Operator*/true, &Input, 1, Functions);
     }
 
     return CreateOverloadedUnaryOp(OpLoc, Opc, Functions, move(input));

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Fri Oct 23 14:23:15 2009
@@ -1561,7 +1561,7 @@
     Functions.insert(FunTmpl);
 }
 
-void Sema::ArgumentDependentLookup(DeclarationName Name,
+void Sema::ArgumentDependentLookup(DeclarationName Name, bool Operator,
                                    Expr **Args, unsigned NumArgs,
                                    FunctionSet &Functions) {
   // Find all of the associated namespaces and classes based on the
@@ -1572,6 +1572,13 @@
                                      AssociatedNamespaces,
                                      AssociatedClasses);
 
+  QualType T1, T2;
+  if (Operator) {
+    T1 = Args[0]->getType();
+    if (NumArgs >= 2)
+      T2 = Args[1]->getType();
+  }
+
   // C++ [basic.lookup.argdep]p3:
   //   Let X be the lookup set produced by unqualified lookup (3.4.1)
   //   and let Y be the lookup set produced by argument dependent
@@ -1608,7 +1615,10 @@
           continue;
       }
 
-      CollectFunctionDecl(Functions, D);
+      FunctionDecl *Fn;
+      if (!Operator || !(Fn = dyn_cast<FunctionDecl>(D)) ||
+          IsAcceptableNonMemberOperatorCandidate(Fn, T1, T2, Context))
+        CollectFunctionDecl(Functions, D);
     }
   }
 }

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Fri Oct 23 14:23:15 2009
@@ -2761,7 +2761,7 @@
   DeclarationName OpName = Context.DeclarationNames.getCXXOperatorName(Op);
   if (S)
     LookupOverloadedOperatorName(Op, S, T1, T2, Functions);
-  ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
+  ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs, Functions);
   AddFunctionCandidates(Functions, Args, NumArgs, CandidateSet);
   AddMemberOperatorCandidates(Op, OpLoc, Args, NumArgs, CandidateSet, OpRange);
   AddBuiltinOperatorCandidates(Op, OpLoc, Args, NumArgs, CandidateSet);
@@ -3908,7 +3908,7 @@
     }
 
   // FIXME: Pass in the explicit template arguments?
-  ArgumentDependentLookup(Name, Args, NumArgs, Functions);
+  ArgumentDependentLookup(Name, /*Operator*/false, Args, NumArgs, Functions);
 
   // Erase all of the candidates we already knew about.
   // FIXME: This is suboptimal. Is there a better way?

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=84963&r1=84962&r2=84963&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Fri Oct 23 14:23:15 2009
@@ -5107,7 +5107,8 @@
   unsigned NumArgs = 1 + (SecondExpr != 0);
   DeclarationName OpName
     = SemaRef.Context.DeclarationNames.getCXXOperatorName(Op);
-  SemaRef.ArgumentDependentLookup(OpName, Args, NumArgs, Functions);
+  SemaRef.ArgumentDependentLookup(OpName, /*Operator*/true, Args, NumArgs,
+                                  Functions);
 
   // Create the overloaded operator invocation for unary operators.
   if (NumArgs == 1 || isPostIncDec) {

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

==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-operator.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-operator.cpp Fri Oct 23 14:23:15 2009
@@ -70,6 +70,34 @@
   float &f4 = (enum1 == enum2);  // expected-error{{non-const lvalue reference to type 'float' cannot be initialized with a temporary of type 'bool'}}
 }
 
+// PR5244 - Argument-dependent lookup would include the two operators below,
+// which would break later assumptions and lead to a crash.
+class pr5244_foo
+{
+  pr5244_foo(int);
+  pr5244_foo(char);
+};
+
+bool operator==(const pr5244_foo& s1, const pr5244_foo& s2);
+bool operator==(char c, const pr5244_foo& s);
+
+enum pr5244_bar
+{
+    pr5244_BAR
+};
+
+class pr5244_baz
+{
+    pr5244_bar quux;
+};
+
+void pr5244_barbaz()
+{
+  pr5244_baz quuux;
+  (void)(pr5244_BAR == quuux.quux);
+}
+
+
 
 struct PostInc {
   PostInc operator++(int);





More information about the cfe-commits mailing list