llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-tidy] report redundant `class`/`struct`/`union`/`enum` tag in declarations with C++

Open firewave opened this issue 4 months ago • 5 comments

struct Struct {};
class Class {};
union Union {};
enum Enum{};

void f()
{
    struct Struct S;
    class Class C;
    union Union U;
    enum Enum E;
}

https://godbolt.org/z/hPGn1ePfx

In C++ it is unnecessary to specify the class/struct/union/enum tag.

firewave avatar Jul 13 '26 10:07 firewave

@llvm/issue-subscribers-clang-tidy

Author: Oliver Stöneberg (firewave)

```cpp struct Struct {}; class Class {}; union Union {}; enum Enum{};

void f() { struct Struct S; class Class C; union Union U; enum Enum E; }


https://godbolt.org/z/hPGn1ePfx

In C++ it is unnecessary to specify the `class`/`struct`/`union`/`enum` tag.
</details>

@llvm/issue-subscribers-c-1

Author: Oliver Stöneberg (firewave)

```cpp struct Struct {}; class Class {}; union Union {}; enum Enum{};

void f() { struct Struct S; class Class C; union Union U; enum Enum E; }


https://godbolt.org/z/hPGn1ePfx

In C++ it is unnecessary to specify the `class`/`struct`/`union`/`enum` tag.
</details>

In C++ it is unnecessary to specify the class/struct/union/enum tag.

The keyword may still be required in some cases:

struct S {} S;

void f() {
    struct S x;
}

chrchr-github avatar Jul 13 '26 11:07 chrchr-github

I am working on this , please assign it to me

purnima-nlp avatar Jul 14 '26 13:07 purnima-nlp

I want to fix this it's so exciting , I need a few more days.

purnima-nlp avatar Jul 16 '26 12:07 purnima-nlp