summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2015-10-20 18:12:08 +0000
committerReid Kleckner <rnk@google.com>2015-10-20 18:12:08 +0000
commit077fe12e5dfe942ec565383c46434476eb31e62c (patch)
treeb332cc461eee964ce6bb1c8091fecbe201133ecf
parent32064024b93d7d0b5225ac576b7684f604c352bf (diff)
downloadbcm5719-llvm-077fe12e5dfe942ec565383c46434476eb31e62c.tar.gz
bcm5719-llvm-077fe12e5dfe942ec565383c46434476eb31e62c.zip
Look through using decls when classifying implicit member access
Clang will now accept this valid C++11 code: struct A { int field; }; struct B : A { using A::field; enum { TheSize = sizeof(field) }; }; Previously we would classify the 'field' reference as something other than a field, and then forget to apply the C++11 rule to allow non-static data member references in unevaluated contexts. This usually arises in class templates that want to reference fields of a dependent base in an unevaluated context outside of an instance method. Such contexts do not allow references to 'this', so the only way to access the field is with a using decl and an implicit member reference. llvm-svn: 250839
-rw-r--r--clang/lib/Sema/SemaExprMember.cpp8
-rw-r--r--clang/test/SemaCXX/using-decl-1.cpp13
2 files changed, 17 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp
index 52dfceccb94..9c345f8a69a 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -102,8 +102,9 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
bool hasNonInstance = false;
bool isField = false;
BaseSet Classes;
- for (LookupResult::iterator I = R.begin(), E = R.end(); I != E; ++I) {
- NamedDecl *D = *I;
+ for (NamedDecl *D : R) {
+ // Look through any using decls.
+ D = D->getUnderlyingDecl();
if (D->isCXXInstanceMember()) {
isField |= isa<FieldDecl>(D) || isa<MSPropertyDecl>(D) ||
@@ -111,8 +112,7 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef,
CXXRecordDecl *R = cast<CXXRecordDecl>(D->getDeclContext());
Classes.insert(R->getCanonicalDecl());
- }
- else
+ } else
hasNonInstance = true;
}
diff --git a/clang/test/SemaCXX/using-decl-1.cpp b/clang/test/SemaCXX/using-decl-1.cpp
index ca532692c1c..5afd15f8b50 100644
--- a/clang/test/SemaCXX/using-decl-1.cpp
+++ b/clang/test/SemaCXX/using-decl-1.cpp
@@ -327,3 +327,16 @@ namespace PR24033 {
using PR24033::st; // expected-error {{target of using declaration conflicts with declaration already in scope}}
}
}
+
+namespace field_use {
+struct A { int field; };
+struct B : A {
+ // Previously Clang rejected this valid C++11 code because it didn't look
+ // through the UsingShadowDecl.
+ using A::field;
+#if __cplusplus < 201103L
+ // expected-error@+2 {{invalid use of non-static data member 'field'}}
+#endif
+ enum { X = sizeof(field) };
+};
+}
OpenPOWER on IntegriCloud