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

Clang suggests wrong attribute placement for enum classes

Open tbaederr opened this issue 3 years ago • 14 comments

Consider this code:

__attribute__((deprecated))
enum  class F {
  Foo,
  Bar
};

clang suggests:

<source>:3:16: warning: attribute 'deprecated' is ignored, place it after "enum" to apply attribute to type declaration [-Wignored-attributes]
__attribute__((deprecated))

Godbolt: https://godbolt.org/z/E4vT1dc57

But placing them after "enum" is wrong, too:

<source>:4:6: error: an attribute list cannot appear here
enum __attribute__((deprecated)) class F {
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~

Godbolt: https://godbolt.org/z/PWvd8jsr5

tbaederr avatar Mar 23 '23 16:03 tbaederr

@llvm/issue-subscribers-good-first-issue

llvmbot avatar Mar 23 '23 16:03 llvmbot

@tbaederr sir maybe this warning is shown because this compiler may not support applying attributes to the underlying type of an enum class. Is it possible? Can you suggest something.

sagar10arya avatar Mar 24 '23 13:03 sagar10arya

The attributes just need to go after 'enum class': https://godbolt.org/z/441Pnq64G

tbaederr avatar Mar 24 '23 14:03 tbaederr

The attributes just need to go after 'enum class': https://godbolt.org/z/441Pnq64G

@tbaederr Yaa, I have been doing the same thing. It has been resolved.

sagar10arya avatar Mar 25 '23 07:03 sagar10arya

@llvmbot @tbaederr can i claim this issue and create a pr to fix it?

antara-gandhi avatar Mar 29 '23 02:03 antara-gandhi

I haven't seen another patch so yes.

tbaederr avatar Mar 29 '23 05:03 tbaederr

@tbaederr @antara-gandhi sorry I have been working on this and I am submitting the patch on this issue just I am getting one problem on submitting patch which I am discussing with mentor.

sagar10arya avatar Mar 29 '23 08:03 sagar10arya

I was working on the patch as well but did not mention in this thread! You can continue @sagar10arya, I will revert back. GCC rightly captures this warning at place,very useful for clang as well. Screenshot from 2023-03-29 14-29-33

Krishna-13-cyber avatar Mar 29 '23 09:03 Krishna-13-cyber

@Krishna-13-cyber cool I will go on with this thanks.

sagar10arya avatar Mar 29 '23 09:03 sagar10arya

I think the error message should be changed to say that it should come after "enum class" instead of "enum".

SamTebbs33 avatar Mar 29 '23 09:03 SamTebbs33

I am an Outreachy applicant and I want to work on this issue.

ipriyanshi1708 avatar Apr 02 '23 10:04 ipriyanshi1708

Can anyone please tell me that whether TST_enum_class is a predefined declaration specifier or not? If not, then how can I identify enum class?

ipriyanshi1708 avatar Apr 09 '23 10:04 ipriyanshi1708

@sagar10arya hey, are you still working on this? If not I could try to pick it up

kmemdump avatar Apr 15 '23 05:04 kmemdump

@sagar10arya hey, are you still working on this? If not I could try to pick it up

Hi! @krishenm94, I have resolved the issue. Now I am working on the tests. https://reviews.llvm.org/D147989

ipriyanshi1708 avatar Apr 15 '23 05:04 ipriyanshi1708