================
@@ -165,12 +166,29 @@ void EnumInitialValueCheck::registerMatchers(MatchFinder
*Finder) {
void EnumInitialValueCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Enum = Result.Nodes.getNodeAs<EnumDecl>("inconsistent")) {
- const DiagnosticBuilder Diag =
- diag(
- Enum->getBeginLoc(),
- "initial values in enum '%0' are not consistent, consider explicit
"
- "initialization of all, none or only the first enumerator")
- << getName(Enum);
+ llvm::SmallVector<StringRef, 4> UninitializedNames;
+ for (const EnumConstantDecl *ECD : Enum->enumerators())
+ if (ECD->getInitExpr() == nullptr && ECD->getDeclName())
+ UninitializedNames.push_back(ECD->getName());
+
+ llvm::SmallString<256> Message;
+ Message = "initial values in enum '%0' are not consistent, "
+ "consider explicit initialization of all, none or "
+ "only the first enumerator";
+ if (!UninitializedNames.empty()) {
+ Message += " (uninitialized enumerators: ";
+ for (size_t I = 0; I < UninitializedNames.size(); ++I) {
+ if (I > 0)
+ Message += (I < UninitializedNames.size() - 1) ? ", " : " and ";
+ Message += "'";
+ Message += UninitializedNames[I];
+ Message += "'";
----------------
vbvictor wrote:
Lets not add list of enumerators to main diagnostic. It becomes big and
unreadable.
Add new note-diagnotics for each incorrect enum value.
So we would have:
```
warning: initial values in enum 'EError' are not consistent, consider explicit
initialization of all, none or only the first enumerator
note: uninitialized enumerator 'EError_a' defined here
note: uninitialized enumerator 'EError_b' defined here
...
```
https://github.com/llvm/llvm-project/pull/176485
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits