This is an archive of the discontinued LLVM Phabricator instance.

Allow lookup into dependent bases in static methods under -fms-compatibility
ClosedPublic

Authored by rnk on Jun 9 2014, 5:28 PM.

Details

Summary

We currently allow unqualified lookup for instance methods but not
static methods because we can't recover with a semantic 'this->'
insertion.

ATL headers have static methods that do unqualified lookup into
dependent base classes. The pattern looks like:

template <typename T> struct Foo : T {
  static int *getBarFromT() { return Bar; }
};

Now we recover as if the user had written:

template <typename T> struct Foo : T {
  static int *getBarFromT() { return Foo::Bar; }
};

... which will eventually look up Bar in T at instantiation time.

Now we also emit a diagnostic in both cases.

Diff Detail

Event Timeline

rnk updated this revision to Diff 10255.Jun 9 2014, 5:28 PM
rnk retitled this revision from to Allow lookup into dependent bases in static methods under -fms-compatibility.
rnk updated this object.
rnk added a reviewer: rsmith.
rnk added a subscriber: Unknown Object (MLST).
majnemer added inline comments.
lib/Sema/SemaExpr.cpp
1940

auto?

rsmith added inline comments.Jun 9 2014, 6:18 PM
lib/Sema/SemaExpr.cpp
1949

This diagnostic seems inappropriate: it says the member was "found by lookup into dependent bases", but we don't know that. All we know is it wasn't found by normal lookup. Maybe rephrase it to only suggest that the name was not found by normal lookup?

1952

This isn't exactly correct. You should also check S.CXXThisTypeOverride; if that's set, then member accesses with this-> are OK even though we're not in a member function. (This happens when parsing a trailing return type or default initializer.)

rnk added inline comments.Jun 10 2014, 4:12 PM
lib/Sema/SemaExpr.cpp
1940

done

1949

What do you think of this diagnostic text?

warning: use of undeclared identifier 'StartWindowProc'; lookup into dependent bases of class template 'Derived' is a Microsoft extension

I'm trying to make it phrase well for -pedantic-errors.

1952

I wasn't trying to be this general, but I went ahead and implemented it with some extra tests.

rnk updated this revision to Diff 10308.Jun 10 2014, 4:13 PM

review

rsmith edited edge metadata.Jun 10 2014, 4:38 PM

Looks fine with some minor tweaks.

include/clang/Basic/DiagnosticSemaKinds.td
3661

Should be ext_...

3665

Hmm, this one too =)

lib/Sema/SemaExpr.cpp
1952

This comment is out of date.

1954

Maybe fold this into the S.Diag call below?

1960–1961

I don't think this comment makes much sense in its new context; maybe just remove it?

rnk added a comment.Jun 10 2014, 4:59 PM

Thanks!

include/clang/Basic/DiagnosticSemaKinds.td
3661

done

lib/Sema/SemaExpr.cpp
1954

done, previously the formatting was horrible

1960–1961

done.

rnk closed this revision.Jun 10 2014, 5:09 PM
rnk updated this revision to Diff 10310.

Closed by commit rL210611 (authored by @rnk).