Skip to content

Bad recommended fix for nodiscard + enum class #163224

@xTachyon

Description

@xTachyon

Link.

Code:

[[nodiscard]] enum class E1 {};

enum [[nodiscard]] class E2 {};

Error:

<source>:1:19: error: misplaced attributes; expected attributes here
    1 | [[nodiscard]] enum class E1 {};
      | ~~~~~~~~~~~~~     ^
      |                   [[nodiscard]]
<source>:3:6: error: an attribute list cannot appear here
    3 | enum [[nodiscard]] class E2 {};
      |      ^~~~~~~~~~~~~

For E1, clang says to put [[nodiscard]] after the enum keyword, but if you do that, it errors on not being valid there either.

My guess is that works with old enums, but was not tested with enum class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"confirmedVerified by a second partyinvalid-code-generationTool (e.g. clang-format) produced invalid code that no longer compiles

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions