readability-trailing-comma false positive on enum with preprocessor #endif
clang-tidy --checks='-*,readability-trailing-comma' test.cpp -- -std=c++20
What happens: the check reports "enum should have a trailing comma" and inserts , right after #endif. But both branches already end their last enumerator with a trailing comma — the fix inserts a stray comma outside the enumerator list, corrupting the source.
Reproducer:
enum class color_t : unsigned {
RED = 0,
GREEN = 1,
BLUE = 2,
CYAN = 3,
#ifdef USE_MAGENTA
LAST = CYAN,
#else
LAST = BLUE,
#endif
};
@llvm/issue-subscribers-clang-tidy
Author: philipp-hackerman
What happens: the check reports "enum should have a trailing comma" and inserts , right after #endif. But both branches already end their last enumerator with a trailing comma — the fix inserts a stray comma outside the enumerator list, corrupting the source.
Reproducer:
enum class color_t : unsigned {
RED = 0,
GREEN = 1,
BLUE = 2,
CYAN = 3,
#ifdef USE_MAGENTA
LAST = CYAN,
#else
LAST = BLUE,
#endif
};
https://godbolt.org/z/j1G4GYEP7