Bad recommended fix for nodiscard + enum class (original) (raw)

Link.

Code:

[[nodiscard]] enum class E1 {};

enum [[nodiscard]] class E2 {};

Error:

:1:19: error: misplaced attributes; expected attributes here 1 | [[nodiscard]] enum class E1 {}; | ~~~~~~~~~~~~~ ^ | [[nodiscard]] :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.