From: Douglas Gregor Date: Tue, 9 Nov 2010 03:31:16 +0000 (+0000) Subject: Fix source locations in unnamed bitfield diagnostic, from Jakub X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90ba6d5cf790c98231c93a63a5b1f7c6a95bd6b6;p=clang Fix source locations in unnamed bitfield diagnostic, from Jakub Wieczorek! Fixes PR8025. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118481 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b33261e4ea..cb88225ada 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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(BW); Expr *Init = static_cast(InitExpr); diff --git a/test/Sema/bitfield.c b/test/Sema/bitfield.c index 5bb194b1f3..49c1c7d443 100644 --- a/test/Sema/bitfield.c +++ b/test/Sema/bitfield.c @@ -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'}} +};