diff options
Diffstat (limited to 'lib/Parse/Parser.cpp')
| -rw-r--r-- | lib/Parse/Parser.cpp | 26 | 
1 files changed, 25 insertions, 1 deletions
| diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 72d653797c60..8aa50a2c7f2a 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -930,7 +930,31 @@ Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,    // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"    // declaration-specifiers init-declarator-list[opt] ';'    if (Tok.is(tok::semi)) { -    ProhibitAttributes(attrs); +    auto LengthOfTSTToken = [](DeclSpec::TST TKind) { +      assert(DeclSpec::isDeclRep(TKind)); +      switch(TKind) { +      case DeclSpec::TST_class: +        return 5; +      case DeclSpec::TST_struct: +        return 6; +      case DeclSpec::TST_union: +        return 5; +      case DeclSpec::TST_enum: +        return 4; +      case DeclSpec::TST_interface: +        return 9; +      default: +        llvm_unreachable("we only expect to get the length of the class/struct/union/enum"); +      } +       +    }; +    // Suggest correct location to fix '[[attrib]] struct' to 'struct [[attrib]]' +    SourceLocation CorrectLocationForAttributes = +        DeclSpec::isDeclRep(DS.getTypeSpecType()) +            ? DS.getTypeSpecTypeLoc().getLocWithOffset( +                  LengthOfTSTToken(DS.getTypeSpecType())) +            : SourceLocation(); +    ProhibitAttributes(attrs, CorrectLocationForAttributes);      ConsumeToken();      RecordDecl *AnonRecord = nullptr;      Decl *TheDecl = Actions.ParsedFreeStandingDeclSpec(getCurScope(), AS_none, | 
