diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-08-28 00:28:14 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-08-28 00:28:14 +0000 |
commit | 6b8e3c02ca44fb6c3738bb0c75859c11a03e30ed (patch) | |
tree | 1f1343ce573a06b3b9a68352ac93b54bc3b270e5 /clang/lib/AST/Decl.cpp | |
parent | bebcbfb46dc7c89d32eb11254123211f87087dca (diff) | |
download | bcm5719-llvm-6b8e3c02ca44fb6c3738bb0c75859c11a03e30ed.tar.gz bcm5719-llvm-6b8e3c02ca44fb6c3738bb0c75859c11a03e30ed.zip |
[c++2a] P0683R1: Permit default member initializers for bit-fields.
This would be trivial, except that our in-memory and serialized representations
for FieldDecls assumed that this can't happen.
llvm-svn: 311867
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index a3bb025eaa9..2137075138f 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3553,8 +3553,7 @@ bool FieldDecl::isAnonymousStructOrUnion() const { unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const { assert(isBitField() && "not a bitfield"); - auto *BitWidth = static_cast<Expr *>(InitStorage.getPointer()); - return BitWidth->EvaluateKnownConstInt(Ctx).getZExtValue(); + return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue(); } unsigned FieldDecl::getFieldIndex() const { @@ -3577,25 +3576,18 @@ unsigned FieldDecl::getFieldIndex() const { } SourceRange FieldDecl::getSourceRange() const { - switch (InitStorage.getInt()) { - // All three of these cases store an optional Expr*. - case ISK_BitWidthOrNothing: - case ISK_InClassCopyInit: - case ISK_InClassListInit: - if (const auto *E = static_cast<const Expr *>(InitStorage.getPointer())) - return SourceRange(getInnerLocStart(), E->getLocEnd()); - // FALLTHROUGH - - case ISK_CapturedVLAType: - return DeclaratorDecl::getSourceRange(); - } - llvm_unreachable("bad init storage kind"); + const Expr *FinalExpr = getInClassInitializer(); + if (!FinalExpr) + FinalExpr = getBitWidth(); + if (FinalExpr) + return SourceRange(getInnerLocStart(), FinalExpr->getLocEnd()); + return DeclaratorDecl::getSourceRange(); } void FieldDecl::setCapturedVLAType(const VariableArrayType *VLAType) { assert((getParent()->isLambda() || getParent()->isCapturedRecord()) && "capturing type in non-lambda or captured record."); - assert(InitStorage.getInt() == ISK_BitWidthOrNothing && + assert(InitStorage.getInt() == ISK_NoInit && InitStorage.getPointer() == nullptr && "bit width, initializer or captured type already set"); InitStorage.setPointerAndInt(const_cast<VariableArrayType *>(VLAType), |