Skip to content

Commit

Permalink
[clang][Diagnostics] Add bitfield source range to zero width diags (#…
Browse files Browse the repository at this point in the history
…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.
```
  • Loading branch information
tbaederr committed Oct 6, 2023
1 parent 8fb83bf commit aad7e0a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18170,7 +18170,8 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,

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

if (Value.isSigned() && Value.isNegative()) {
if (FieldName)
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Misc/misc-source-ranges.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-print-source-range-info %s 2>&1 | FileCheck %s

struct S {
char a : 12 - 12;
};
// CHECK: misc-source-ranges.cpp:[[@LINE-2]]:8:{[[@LINE-2]]:12-[[@LINE-2]]:19}

0 comments on commit aad7e0a

Please sign in to comment.