Skip to content

Commit cf69cb0

Browse files
committed
Mention requirements in FieldDecl::getBitwidthValue()
1 parent fe5309d commit cf69cb0

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,6 +3143,8 @@ class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
31433143

31443144
/// Computes the bit width of this field, if this is a bit field.
31453145
/// May not be called on non-bitfields.
3146+
/// Note that in order to successfully use this function, the bitwidth
3147+
/// expression must be a ConstantExpr with a valid integer result set.
31463148
unsigned getBitWidthValue() const;
31473149

31483150
/// Set the bit-field width for this member.

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,6 +4603,7 @@ unsigned FieldDecl::getBitWidthValue() const {
46034603
assert(isBitField() && "not a bitfield");
46044604
assert(isa<ConstantExpr>(getBitWidth()));
46054605
assert(cast<ConstantExpr>(getBitWidth())->hasAPValueResult());
4606+
assert(cast<ConstantExpr>(getBitWidth())->getAPValueResult().isInt());
46064607
return cast<ConstantExpr>(getBitWidth())
46074608
->getAPValueResult()
46084609
.getInt()

0 commit comments

Comments
 (0)