Attributes are accepted at invalid locations within declarations
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following program demonstrates the issue:
```cpp
using T=int;
namespace N{
templateusing A=T;
}
struct S{
using T=int;
};
union U{};
enum E{};
extern[[]]::T x;
extern[[]]typename::T x;
extern[[]]N::Ax;
extern[[]]S::T x;
extern[[]]decltype(S())::T x;
extern[[]]decltype(0)x;
extern[[]]decltype(auto)x=0;//only decltype(auto) has this issue
extern[[]]struct S y;
extern[[]]class S y;
extern[[]]union U z;
extern[[]]enum E w;
extern[[]]struct{}v;
extern[[]]union{}u;
extern[[]]enum{}t;
int main(){}
```
The same issues also appear in C:
```c
enum E:int;
extern[[]]struct S x;
extern[[]]union U y;
extern[[]]enum E z;
extern[[]]struct{int m;}w;
extern[[]]union{int m;}v;
extern[[]]enum{E}u;
int main(){}
```
Attributes are not allowed in the middle of declaration specifiers, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114315. What occurs before the attribute does not seem to matter, only what occurs after:
```cpp
using T=int;
extern[[]]::T x;//accepted
const extern[[]]::T y;//accepted
extern const[[]]::T y;//accepted
extern[[]]const::T y;//rejected
extern[[]]::T const y;//rejected
int main(){}
```
All attributes used in the presented programs are invalid.
Contributor guide
Research direction
Start by compiling the C++ and C reproducers and checking which declaration forms accept the invalid attributes. No source file or test is named; trace the declaration-specifier and attribute-placement handling in the compiler. Done means invalid placements are rejected in the shown cases while valid placements remain accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100