diff options
author | Melanie Blower <melanie.blower@intel.com> | 2019-11-08 10:14:51 -0800 |
---|---|---|
committer | Melanie Blower <melanie.blower@intel.com> | 2019-11-08 10:17:06 -0800 |
commit | 759948467ea3181615d44d80f74ffeb260180fd0 (patch) | |
tree | 813003353dd8d69d11b1fb46f33b860945f6615b /clang/lib/AST/Expr.cpp | |
parent | 7f92d66f378574ab2a02935b6614560ae9000539 (diff) | |
download | bcm5719-llvm-759948467ea3181615d44d80f74ffeb260180fd0.tar.gz bcm5719-llvm-759948467ea3181615d44d80f74ffeb260180fd0.zip |
Reapply "Fix crash on switch conditions of non-integer types in templates"
This patch reapplies commit 76945821b9cad3. The first version broke
buildbots due to clang-tidy test fails. The fails are because some
errors in templates are now diagnosed earlier (does not wait till
instantiation). I have modified the tests to add checks for these
diagnostics/prevent these diagnostics. There are no additional code
changes.
Summary of code changes:
Clang currently crashes for switch statements inside a template when the
condition is a non-integer field member because contextual implicit
conversion is skipped when parsing the condition. This conversion is
however later checked in an assert when the case statement is handled.
The conversion is skipped when parsing the condition because
the field member is set as type-dependent based on its containing class.
This patch sets the type dependency based on the field's type instead.
This patch fixes Bug 40982.
Reviewers: rnk, gribozavr2
Patch by: Elizabeth Andrews (eandrews)
Differential revision: https://reviews.llvm.org/D69950
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 3438c3aadc6..00ba329642c 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1675,6 +1675,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()) { |