diff options
author | Elizabeth Andrews <elizabeth.andrews@intel.com> | 2019-08-13 15:53:19 +0000 |
---|---|---|
committer | Elizabeth Andrews <elizabeth.andrews@intel.com> | 2019-08-13 15:53:19 +0000 |
commit | 76945821b9cad3baebad5c36ae00ab173f8529c6 (patch) | |
tree | a3e44347cfdaf3a2cabe88257f51328504c15971 /clang/lib/AST/Expr.cpp | |
parent | 0a04a062500e2c6d5b92b59c545db3f45e9daffe (diff) | |
download | bcm5719-llvm-76945821b9cad3baebad5c36ae00ab173f8529c6.tar.gz bcm5719-llvm-76945821b9cad3baebad5c36ae00ab173f8529c6.zip |
Fix crash on switch conditions of non-integer types in templates
Clang currently crashes for switch statements inside a template when
the condition is a non-integer field. The crash is due to incorrect
type-dependency of field. Type-dependency of member expressions is
currently set based on the containing class. This patch changes this for
'members of the current instantiation' to set the type dependency based
on the member's type instead.
A few lit tests started to fail once I applied this patch because errors
are now diagnosed earlier (does not wait till instantiation). I've modified
these tests in this patch as well.
Patch fixes PR#40982
Differential Revision: https://reviews.llvm.org/D61027
llvm-svn: 368706
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r-- | clang/lib/AST/Expr.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index d2730d3e26d..70bd42cfa51 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1669,6 +1669,15 @@ MemberExpr *MemberExpr::Create( MemberExpr *E = new (Mem) MemberExpr(Base, IsArrow, OperatorLoc, MemberDecl, NameInfo, T, VK, OK, NOUR); + if (FieldDecl *Field = dyn_cast<FieldDecl>(MemberDecl)) { + DeclContext *DC = MemberDecl->getDeclContext(); + // dyn_cast_or_null is used to handle objC variables which do not + // have a declaration context. + CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC); + if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) + E->setTypeDependent(T->isDependentType()); + } + if (HasQualOrFound) { // FIXME: Wrong. We should be looking at the member declaration we found. if (QualifierLoc && QualifierLoc.getNestedNameSpecifier()->isDependent()) { |