[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

Jerin Philip via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 22 03:41:26 PDT 2023


================
@@ -94,7 +94,7 @@ class AttributeCommonInfo {
           IsRegularKeywordAttribute(IsRegularKeywordAttribute) {}
     constexpr Form(tok::TokenKind Tok)
         : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
-          IsAlignas(Tok == tok::kw_alignas),
+          IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas),
----------------
jerinphilip wrote:

The other place to recover the `_Alignas` vs `alignas` is `SpellingIndex`. But the following (removed) comment still applies (regarding `SpellingIndex`):

[[clang] Reject non-declaration C++11 attributes on declarations](https://github.com/llvm/llvm-project/commit/8c7b64b5ae2a09027c38db969a04fc9ddd0cd6bb)

```cpp
    // FIXME: Use a better mechanism to determine this
    // We use this in `isCXX11Attribute` below, so it _should_ only return
    // true for the `alignas` spelling, but it currently also returns true
    // for the `_Alignas` spelling, which only exists in C11. Distinguishing
    // between the two is important because they behave differently:
    // - `alignas` may only appear in the attribute-specifier-seq before
    //   the decl-specifier-seq and is therefore associated with the
    //   declaration.
    // - `_Alignas` may appear anywhere within the declaration-specifiers
    //   and is therefore associated with the `DeclSpec`.
    // It's not clear how best to fix this:
    // - We have the necessary information in the form of the `SpellingIndex`,
    //   but we would need to compare against AlignedAttr::Keyword_alignas,
    //   and we can't depend on clang/AST/Attr.h here.
    // - We could test `getAttrName()->getName() == "alignas"`, but this is
    //   inefficient.
```

https://github.com/llvm/llvm-project/pull/65638


More information about the cfe-commits mailing list