[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)
Jerin Philip via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 20 10:51:08 PDT 2023
================
@@ -186,14 +186,14 @@ class AttributeCommonInfo {
bool isGNUScope() const;
bool isClangScope() const;
- bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
-
+ bool isAlignas() const { return IsAlignas; }
+ bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
----------------
jerinphilip wrote:
Trying to guess based on surroundings, the `AttributeCommonInfo::is<Method>(...)` corresponds consistently to [`Syntax`](https://github.com/llvm/llvm-project/blob/4345baaa02c5e2d27a727e8b2cf22d95b2842cd9/clang/include/clang/Basic/AttributeCommonInfo.h#L26-L27) enum save `isCXX11Attribute`, and assuming consistency is preferred a method with the name `isCXX11Attribute` should only tell if it corresponds to `AS_CXX11`, which is `[[ ]]` when C++ is used (consistent with `is{C23,GNU,Declspec,Microsoft,...}Attribute()`).
This function body appears to imply what is defined as `attribute-specifier` ([C++](https://eel.is/c++draft/dcl.attr#nt:attribute-specifier)) prior to this change. So it may be worth renaming this and such intended usages to `isCXXAttributeSpecifier() = [[]] | alignas(..) ` which can be inferred from this instance to improve.
In the [C23-draft](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf) I picked off the Wikipedia page, `alignas` appears to be a _keyword_ part of an `alignment-specifier`, while `attribute-specifier` only includes `[[ ]]`. Common ancestor for `attribute-specifier`, `alignment-specifier` appears to be something called a `specifier-qualifier-list`. Based on the below details, I have a feeling it is okay to treat this as `isCAttributeSpecifier() == [[ ]] | alignas | _Alignas ` for practical purposes, moving the term `alignment-specifier` around.
<details> <summary> C (grammar) </summary>
```
specifier-qualifier-list:
type-specifier-qualifier attribute-specifier-sequence_opt
type-specifier-qualifier specifier-qualifier-list
attribute-specifier-sequence:
attribute-specifier-sequence_opt attribute-specifier
attribute-specifier:
[[ attribute-list ]]
type-specifier-qualifier:
type-specifier
type-qualifier
alignment-specifier
alignment-specifier:
alignas ( type-name )
alignas ( constant-expression )
```
</details>
https://github.com/llvm/llvm-project/pull/65638
More information about the cfe-commits
mailing list