Skip to content

Commit 808f8a6

Browse files
elizabethandrewszmodem
authored andcommitted
Fix type-dependency of bitfields in templates
This patch is a follow up to 878a24e. 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 a58017e)
1 parent b3cf704 commit 808f8a6

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clang/lib/AST/Expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,11 @@ MemberExpr *MemberExpr::Create(
16851685
CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(DC);
16861686
if (RD && RD->isDependentContext() && RD->isCurrentInstantiation(DC))
16871687
E->setTypeDependent(T->isDependentType());
1688+
1689+
// Bitfield with value-dependent width is type-dependent.
1690+
FieldDecl *FD = dyn_cast<FieldDecl>(MemberDecl);
1691+
if (FD && FD->isBitField() && FD->getBitWidth()->isValueDependent())
1692+
E->setTypeDependent(true);
16881693
}
16891694

16901695
if (HasQualOrFound) {

clang/test/SemaTemplate/enum-argument.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
23

34
enum Enum { val = 1 };
45
template <Enum v> struct C {
@@ -30,7 +31,7 @@ namespace rdar8020920 {
3031
unsigned long long bitfield : e0;
3132

3233
void f(int j) {
33-
bitfield + j; // expected-warning {{expression result unused}}
34+
bitfield + j;
3435
}
3536
};
3637
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify %s
2+
// expected-no-diagnostics
3+
4+
template <int b>
5+
class A {
6+
int c : b;
7+
8+
public:
9+
void f() {
10+
if (c)
11+
;
12+
}
13+
};

0 commit comments

Comments
 (0)