Skip to content

Conversation

@tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Oct 5, 2023

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.

@tbaederr tbaederr requested review from AaronBallman and cjdb October 5, 2023 14:20
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 5, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 5, 2023

@llvm/pr-subscribers-clang

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/68312.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaDecl.cpp (+2-1)
  • (added) clang/test/Misc/misc-source-ranges.cpp (+7)
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 28d9a0ac654b81f..8fff33c49f2e5c7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18161,7 +18161,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)
diff --git a/clang/test/Misc/misc-source-ranges.cpp b/clang/test/Misc/misc-source-ranges.cpp
new file mode 100644
index 000000000000000..7a9d9d057dac407
--- /dev/null
+++ b/clang/test/Misc/misc-source-ranges.cpp
@@ -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}
+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants