| Issue |
71544
|
| Summary |
[FR] Alter clang-tidy check "performance-enum-size" to not trigger if enum class is empty
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
FalcoGer
|
An `enum class` can be used as a convenient type safe wrapper for integral values. Doing so would leave the `enum class` without enum constants. For example.
```c++
#include <map>
enum class ServerID : int {};
enum class ClientID : int {};
class Session{};
class Control
{
private:
std::map<ClientID, Session> m_clientSessions {};
std::map<ServerID, Session> m_serverSessions {};
public:
void CloseClient(ClientID clientID)
{
m_clientSessions.erase(clientID);
}
void CloseServer(ServerID serverID)
{
// Compiler error is good! Wouldn't happen with type alias
// using ServerID = int;
m_clientSessions.erase(serverID);
}
};
```
However, `performance-enum-size` currently flags those enums.
> Enum 'ServerID' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size (clang-tidy performance-enum-size)
To allow the use of this idom, I would like if either `performance-enum-size` didn't check if the enum has no members, or if there were an option that could be set in clang's config.yaml `Diagnostics.ClangTidy.CheckOptions."performance-enum-size.IgnoreEmptyEnumClasses"`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs