diff options
author | Elizabeth Andrews <elizabeth.andrews@intel.com> | 2020-02-12 11:30:02 -0800 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-02-13 09:26:58 +0100 |
commit | 808f8a632f8bc12830157c57461ae8f848c566a3 (patch) | |
tree | 652442f7d479965135f5f513c02d2f8032be1be7 | |
parent | b3cf70427eb1e97d9b89ba6e9298c280c8a32c74 (diff) | |
download | llvm-808f8a632f8bc12830157c57461ae8f848c566a3.tar.gz |
Fix type-dependency of bitfields in templates
This patch is a follow up to 878a24ee244a24. Name of bitfields
with value-dependent width should be set as type-dependent. This
patch adds the required value-dependency check and sets the
type-dependency accordingly.
Patch fixes PR44886
Differential revision: https://reviews.llvm.org/D72242
(cherry picked from commit a58017e5cae5be948fd1913b68d46553e87aa622)
-rw-r--r-- | clang/lib/AST/Expr.cpp | 5 | ||||
-rw-r--r-- | clang/test/SemaTemplate/enum-argument.cpp | 3 | ||||
-rw-r--r-- | clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp | 13 |
3 files changed, 20 insertions, 1 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 835198958766..fea7d606f261 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1685,6 +1685,11 @@ MemberExpr *MemberExpr::Create( CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC); if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC)) E->setTypeDependent(T->isDependentType()); + + // Bitfield with value-dependent width is type-dependent. + FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl); + if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent()) + E->setTypeDependent(true); } if (HasQualOrFound) { diff --git a/clang/test/SemaTemplate/enum-argument.cpp b/clang/test/SemaTemplate/enum-argument.cpp index a79ed8403e9f..7ff419613990 100644 --- a/clang/test/SemaTemplate/enum-argument.cpp +++ b/clang/test/SemaTemplate/enum-argument.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics enum Enum { val = 1 }; template <Enum v> struct C { @@ -30,7 +31,7 @@ namespace rdar8020920 { unsigned long long bitfield : e0; void f(int j) { - bitfield + j; // expected-warning {{expression result unused}} + bitfield + j; } }; } diff --git a/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp new file mode 100644 index 000000000000..873e4d48e837 --- /dev/null +++ b/clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp @@ -0,0 +1,13 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics + +template <int b> +class A { + int c : b; + +public: + void f() { + if (c) + ; + } +}; |