]> granicus.if.org Git - clang/commitdiff
Fix source locations in unnamed bitfield diagnostic, from Jakub
authorDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 03:31:16 +0000 (03:31 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 9 Nov 2010 03:31:16 +0000 (03:31 +0000)
Wieczorek! Fixes PR8025.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118481 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
test/Sema/bitfield.c

index b33261e4ea1e3b4b877790710e27fb5de97f8554..cb88225adaf5cb65d42518d11e43513a2e57941e 100644 (file)
@@ -843,6 +843,11 @@ Sema::ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, Declarator &D,
   DeclarationNameInfo NameInfo = GetNameForDeclarator(D);
   DeclarationName Name = NameInfo.getName();
   SourceLocation Loc = NameInfo.getLoc();
+
+  // For anonymous bitfields, the location should point to the type.
+  if (Loc.isInvalid())
+    Loc = D.getSourceRange().getBegin();
+
   Expr *BitWidth = static_cast<Expr*>(BW);
   Expr *Init = static_cast<Expr*>(InitExpr);
 
index 5bb194b1f3a9bd5f53ce13d92c71a995302ca530..49c1c7d443617d51d9f73c4309f67a99cb4203ee 100644 (file)
@@ -34,3 +34,7 @@ struct {unsigned x : 2;} x2;
 __typeof__((x.x+=1)+1) y;
 __typeof__(x.x<<1) y;
 int y;
+
+struct PR8025 {
+  double : 2; // expected-error{{anonymous bit-field has non-integral type 'double'}}
+};