Clang error: bit-field A has non-integral type B (err_not_integral_type_bitfield)
Jump to navigation
Jump to search
Text | error: bit-field A has non-integral type B |
---|---|
Type | Error |
Category | Semantic Issue |
Internal Id | err_not_integral_type_bitfield |
Internal Message | bit-field %0 has non-integral type %1
|
Regular Expression | (?:error|fatal error)\: bit\-field (.*?) has non\-integral type (.*?)
|
First Commit | 2009-03-04 b1c4d5507fad The basic representation of diagnostics information in tablegen format, plus (uncommented and incomp... |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
struct S {
float f : 1; // non-integral type 'float'
};
int main() {
return 0;
}
| |
Compiler Output |
<source>:2:11: error: bit-field 'f' has non-integral type 'float' |
Clang Internals (17.0.6)
Git Commit Message
The basic representation of diagnostics information in tablegen format, plus (uncommented and incomplete) test conversions of the existing def files to this format. llvm-svn: 66064
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaDecl.cpp (line 17898)
// Note that FieldName may be null for anonymous bitfields.
ExprResult Sema::VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, QualType FieldTy, bool IsMsStruct, Expr *BitWidth) {
// ...
// C99 6.7.2.1p4 - verify the field type.
// C++ 9.6p3: A bit-field shall have integral or enumeration type.
if (!FieldTy->isDependentType() && !FieldTy->isIntegralOrEnumerationType()) {
// ...
if (FieldName)
return Diag(FieldLoc, diag::err_not_integral_type_bitfield) << FieldName << FieldTy << BitWidth->getSourceRange();
clang/lib/Sema/SemaDeclCXX.cpp (line 3634)
/// ActOnCXXMemberDeclarator - This is invoked when a C++ class member
/// declarator is parsed. 'AS' is the access specifier, 'BW' specifies the
/// bitfield width if there is one, 'InitExpr' specifies the initializer if
/// one has been parsed, and 'InitStyle' is set if an in-class initializer is
/// present (but parsing it has been deferred).
NamedDecl *Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, Expr *BW, const VirtSpecifiers &VS, InClassInitStyle InitStyle) {
// ...
if (isInstField) {
// ...
} else {
// ...
// Non-instance-fields can't have a bitfield.
if (BitWidth) {
if (Member->isInvalidDecl()) {
// ...
} else if (isa<VarDecl>(Member) || isa<VarTemplateDecl>(Member)) {
// ...
} else if (isa<TypedefDecl>(Member)) {
// ...
} else {
// ...
Diag(Loc, diag::err_not_integral_type_bitfield) << Name << cast<ValueDecl>(Member)->getType() << BitWidth->getSourceRange();
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/SemaTemplate/instantiate-field.cpp
- clang/test/SemaTemplate/instantiate-field.cpp:8:5: error: bit-field 'bitfield' has non-integral type 'float'