This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix operator lookup to consider local extern declarations.
ClosedPublic

Authored by EricWF on Jul 12 2017, 2:54 AM.

Details

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.

Diff Detail

Event Timeline

EricWF created this revision.Jul 12 2017, 2:54 AM
EricWF updated this revision to Diff 106166.Jul 12 2017, 3:30 AM

Add more appropriate test.

EricWF updated this revision to Diff 106168.Jul 12 2017, 3:37 AM
EricWF edited the summary of this revision. (Show Details)

@rsmith Ping. This should be super simple to review.

rsmith added inline comments.Jul 30 2017, 4:03 PM
lib/Sema/SemaLookup.cpp
229

This isn't right; IDNS_LocalExtern finds local extern declarations in the namespace scope enclosing their declaration, so this will incorrectly allow:

struct A {} a;
void f() { extern bool operator==(A, A); }
bool b = a == a;

As far as I can see, the problem is that the constructor of FindLocalExternScope only enables finding local extern declarations if we're also looking for IDNS_Ordinary; the right fix would presumably be for it to also check for IDNS_NonMemberOperator.

EricWF updated this revision to Diff 108845.Jul 30 2017, 4:20 PM
  • Address issues in inline comments. The patch should be ready to go now :-)
rsmith accepted this revision.Jul 30 2017, 5:19 PM

LGTM, thanks!

This revision is now accepted and ready to land.Jul 30 2017, 5:19 PM
EricWF closed this revision.Jul 30 2017, 5:25 PM

@rsmith Should this be considered for the 5.0 release?