Author: ericwf
Date: Sun Jul 30 17:24:28 2017
New Revision: 309530

URL: http://llvm.org/viewvc/llvm-project?rev=309530&view=rev
Log:
[Sema] Fix operator lookup to consider local extern declarations.

Summary:
Previously Clang was not considering operator declarations that occur at 
function scope. This is incorrect according to [over.match.oper]p3
> The set of non-member candidates is the result of the unqualified lookup of 
> operator@ in the context of the expression according to the usual rules for 
> name lookup in unqualified function calls.

This patch changes operator name lookup to consider block scope declarations.
This patch fixes PR27027.




Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D35297

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/SemaCXX/overloaded-operator.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=309530&r1=309529&r2=309530&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sun Jul 30 17:24:28 2017
@@ -1031,7 +1031,8 @@ struct FindLocalExternScope {
   FindLocalExternScope(LookupResult &R)
       : R(R), OldFindLocalExtern(R.getIdentifierNamespace() &
                                  Decl::IDNS_LocalExtern) {
-    R.setFindLocalExtern(R.getIdentifierNamespace() & Decl::IDNS_Ordinary);
+    R.setFindLocalExtern(R.getIdentifierNamespace() &
+                         (Decl::IDNS_Ordinary | Decl::IDNS_NonMemberOperator));
   }
   void restore() {
     R.setFindLocalExtern(OldFindLocalExtern);

Modified: cfe/trunk/test/SemaCXX/overloaded-operator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-operator.cpp?rev=309530&r1=309529&r2=309530&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-operator.cpp (original)
+++ cfe/trunk/test/SemaCXX/overloaded-operator.cpp Sun Jul 30 17:24:28 2017
@@ -531,3 +531,22 @@ namespace NoADLForMemberOnlyOperators {
     b3 / 0; // expected-note {{in instantiation of}} expected-error {{invalid 
operands to}}
   }
 }
+
+
+namespace PR27027 {
+  template <class T> void operator+(T, T) = delete; // expected-note 4 
{{candidate}}
+  template <class T> void operator+(T) = delete; // expected-note 4 
{{candidate}}
+
+  struct A {} a_global;
+  void f() {
+    A a;
+    +a; // expected-error {{overload resolution selected deleted operator '+'}}
+    a + a; // expected-error {{overload resolution selected deleted operator 
'+'}}
+    bool operator+(A);
+    extern bool operator+(A, A);
+    +a; // OK
+    a + a;
+  }
+  bool test_global_1 = +a_global; // expected-error {{overload resolution 
selected deleted operator '+'}}
+  bool test_global_2 = a_global + a_global; // expected-error {{overload 
resolution selected deleted operator '+'}}
+}


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to