Skip to content

Commit aad7e0a

Browse files
authored
[clang][Diagnostics] Add bitfield source range to zero width diags (#68312)
Before: ``` array.cpp:157:8: error: named bit-field 'a' has zero width 157 | char a : 12 - 12; | ^ 1 error generated. ``` After: ``` array.cpp:157:8: error: named bit-field 'a' has zero width 157 | char a : 12 - 12; | ^ ~~~~~~~ 1 error generated. ```
1 parent 8fb83bf commit aad7e0a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Sema/SemaDecl.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18170,7 +18170,8 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
1817018170

1817118171
// Zero-width bitfield is ok for anonymous field.
1817218172
if (Value == 0 && FieldName)
18173-
return Diag(FieldLoc, diag::err_bitfield_has_zero_width) << FieldName;
18173+
return Diag(FieldLoc, diag::err_bitfield_has_zero_width)
18174+
<< FieldName << BitWidth->getSourceRange();
1817418175

1817518176
if (Value.isSigned() && Value.isNegative()) {
1817618177
if (FieldName)
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s
2+
3+
struct S {
4+
char a : 12 - 12;
5+
};
6+
// CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}
7+

0 commit comments

Comments
 (0)