[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates
Elizabeth Andrews via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 12 13:38:12 PST 2020
This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa58017e5cae5: Fix type-dependency of bitfields in templates (authored by eandrews).
Herald added a project: clang.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D72242/new/
https://reviews.llvm.org/D72242
Files:
clang/lib/AST/Expr.cpp
clang/test/SemaTemplate/enum-argument.cpp
clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===================================================================
--- /dev/null
+++ 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)
+ ;
+ }
+};
Index: clang/test/SemaTemplate/enum-argument.cpp
===================================================================
--- clang/test/SemaTemplate/enum-argument.cpp
+++ 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 @@
unsigned long long bitfield : e0;
void f(int j) {
- bitfield + j; // expected-warning {{expression result unused}}
+ bitfield + j;
}
};
}
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1680,6 +1680,11 @@
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72242.244270.patch
Type: text/x-patch
Size: 1561 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200212/2b0b4926/attachment.bin>
More information about the cfe-commits
mailing list