Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang rejects valid int iarr [10] alignas(Required); #106551

Open
ranaanoop opened this issue Aug 29, 2024 · 2 comments
Open

Clang rejects valid int iarr [10] alignas(Required); #106551

ranaanoop opened this issue Aug 29, 2024 · 2 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid

Comments

@ranaanoop
Copy link

ranaanoop commented Aug 29, 2024

The following valid program is rejected by clang but accepted by both gcc and msvc. Demo

constexpr std::size_t Required=16;

int iarr [10] alignas(Required); 

Clang says:

<source>:16:15: error: 'alignas' attribute cannot be applied to types
   16 | int iarr [10] alignas(Required); 
      |          

Note that if you move [10] to after alignas(Required) then clang also starts accepting.

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Aug 29, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid and removed clang Clang issues not falling into any other category labels Aug 29, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 29, 2024

@llvm/issue-subscribers-clang-frontend

Author: Anoop Rana (ranaanoop)

The following valid program is rejected by clang but accepted by both gcc and msvc. [Demo](https://godbolt.org/z/j54c4KxMa)
constexpr std::size_t Required=16;

int iarr [10] alignas(Required); 

Clang says:

&lt;source&gt;:16:15: error: 'alignas' attribute cannot be applied to types
   16 | int iarr [10] alignas(Required); 
      |          

Note that if you move [10] to after alignas(Required) then clang also starts accepting.

@MitalAshok
Copy link
Contributor

GCC/MSVC also accept int iarr [10] alignas(16) [14];

My understanding is that in that position, alignas appertains to the array type and this should be invalid.

https://eel.is/c++draft/dcl.attr.grammar#5.sentence-1

https://eel.is/c++draft/dcl.dcl#ntref:attribute-specifier-seq______________________

Clang does accept int iarr2 [10] __attribute__((aligned(16)));, as described here https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#All-other-attributes:

For compatibility with existing code written for compiler versions that did not implement attributes on nested declarators, some laxity is allowed in the placing of attributes. [...]. If an attribute that only applies to declarations is applied to the type of a declaration, it is treated as applying to that declaration

But does not accept int iarr3 [10] [[gnu::aligned(16)]]; like gcc does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" rejects-valid
Projects
None yet
Development

No branches or pull requests

4 participants