forked from OSchip/llvm-project
Fix diagnostic for static methods referencing fields from using decls
Previously we thought the instance member was a function, not a field, and we'd say something silly like: t.cpp:4:27: error: call to non-static member function without an object argument static int f() { return n; } ^ Noticed in PR21923. llvm-svn: 224480
This commit is contained in:
parent
323ddf97ba
commit
ae628965c4
|
@ -90,7 +90,6 @@ enum IMAKind {
|
||||||
/// conservatively answer "yes", in which case some errors will simply
|
/// conservatively answer "yes", in which case some errors will simply
|
||||||
/// not be caught until template-instantiation.
|
/// not be caught until template-instantiation.
|
||||||
static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
|
static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
|
||||||
Scope *CurScope,
|
|
||||||
const LookupResult &R) {
|
const LookupResult &R) {
|
||||||
assert(!R.empty() && (*R.begin())->isCXXClassMember());
|
assert(!R.empty() && (*R.begin())->isCXXClassMember());
|
||||||
|
|
||||||
|
@ -205,6 +204,9 @@ static void diagnoseInstanceReference(Sema &SemaRef,
|
||||||
SourceRange Range(Loc);
|
SourceRange Range(Loc);
|
||||||
if (SS.isSet()) Range.setBegin(SS.getRange().getBegin());
|
if (SS.isSet()) Range.setBegin(SS.getRange().getBegin());
|
||||||
|
|
||||||
|
// Look through using shadow decls and aliases.
|
||||||
|
Rep = Rep->getUnderlyingDecl();
|
||||||
|
|
||||||
DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext();
|
DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext();
|
||||||
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC);
|
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC);
|
||||||
CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr;
|
CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr;
|
||||||
|
@ -237,7 +239,7 @@ Sema::BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS,
|
||||||
SourceLocation TemplateKWLoc,
|
SourceLocation TemplateKWLoc,
|
||||||
LookupResult &R,
|
LookupResult &R,
|
||||||
const TemplateArgumentListInfo *TemplateArgs) {
|
const TemplateArgumentListInfo *TemplateArgs) {
|
||||||
switch (ClassifyImplicitMemberAccess(*this, CurScope, R)) {
|
switch (ClassifyImplicitMemberAccess(*this, R)) {
|
||||||
case IMA_Instance:
|
case IMA_Instance:
|
||||||
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true);
|
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true);
|
||||||
|
|
||||||
|
|
|
@ -255,3 +255,11 @@ namespace TypoCorrectTemplateMember {
|
||||||
using A::goobar; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}}
|
using A::goobar; // expected-error {{no member named 'goobar' in 'TypoCorrectTemplateMember::A'; did you mean 'foobar'?}}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace use_instance_in_static {
|
||||||
|
struct A { int n; };
|
||||||
|
struct B : A {
|
||||||
|
using A::n;
|
||||||
|
static int f() { return n; } // expected-error {{invalid use of member 'n' in static member function}}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue