r224480 - Fix diagnostic for static methods referencing fields from using decls
Reid Kleckner
reid at kleckner.net
Wed Dec 17 16:42:51 PST 2014
Author: rnk
Date: Wed Dec 17 18:42:51 2014
New Revision: 224480
URL: http://llvm.org/viewvc/llvm-project?rev=224480&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/test/SemaCXX/using-decl-1.cpp
Modified: cfe/trunk/lib/Sema/SemaExprMember.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprMember.cpp?rev=224480&r1=224479&r2=224480&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprMember.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprMember.cpp Wed Dec 17 18:42:51 2014
@@ -90,7 +90,6 @@ enum IMAKind {
/// conservatively answer "yes", in which case some errors will simply
/// not be caught until template-instantiation.
static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
- Scope *CurScope,
const LookupResult &R) {
assert(!R.empty() && (*R.begin())->isCXXClassMember());
@@ -205,6 +204,9 @@ static void diagnoseInstanceReference(Se
SourceRange Range(Loc);
if (SS.isSet()) Range.setBegin(SS.getRange().getBegin());
+ // Look through using shadow decls and aliases.
+ Rep = Rep->getUnderlyingDecl();
+
DeclContext *FunctionLevelDC = SemaRef.getFunctionLevelDeclContext();
CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(FunctionLevelDC);
CXXRecordDecl *ContextClass = Method ? Method->getParent() : nullptr;
@@ -237,7 +239,7 @@ Sema::BuildPossibleImplicitMemberExpr(co
SourceLocation TemplateKWLoc,
LookupResult &R,
const TemplateArgumentListInfo *TemplateArgs) {
- switch (ClassifyImplicitMemberAccess(*this, CurScope, R)) {
+ switch (ClassifyImplicitMemberAccess(*this, R)) {
case IMA_Instance:
return BuildImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, true);
Modified: cfe/trunk/test/SemaCXX/using-decl-1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/using-decl-1.cpp?rev=224480&r1=224479&r2=224480&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/using-decl-1.cpp (original)
+++ cfe/trunk/test/SemaCXX/using-decl-1.cpp Wed Dec 17 18:42:51 2014
@@ -255,3 +255,11 @@ namespace TypoCorrectTemplateMember {
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}}
+};
+}
More information about the cfe-commits
mailing list