Skip to content

Commit 7f69cd5

Browse files
authored
[clang-doc] remove default label on some switches (#143919)
LLVM style prefers no default label on fully covered switches to warn if new enums are added. This patch removes the default label for that purpose or uses IT_default instead of default if that was the only enum not covered.
1 parent d7e64d9 commit 7f69cd5

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ static llvm::Error decodeRecord(const Record &R, AccessSpecifier &Field,
5454
case AS_none:
5555
Field = (AccessSpecifier)R[0];
5656
return llvm::Error::success();
57-
default:
58-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
59-
"invalid value for AccessSpecifier");
6057
}
58+
llvm_unreachable("invalid value for AccessSpecifier");
6159
}
6260

6361
static llvm::Error decodeRecord(const Record &R, TagTypeKind &Field,

clang-tools-extra/clang-doc/BitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ bool ClangDocBitcodeWriter::dispatchInfoForWrite(Info *I) {
664664
case InfoType::IT_typedef:
665665
emitBlock(*static_cast<clang::doc::TypedefInfo *>(I));
666666
break;
667-
default:
667+
case InfoType::IT_default:
668668
llvm::errs() << "Unexpected info, unable to write.\n";
669669
return true;
670670
}

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ mergeInfos(std::vector<std::unique_ptr<Info>> &Values) {
143143
return reduce<FunctionInfo>(Values);
144144
case InfoType::IT_typedef:
145145
return reduce<TypedefInfo>(Values);
146-
default:
146+
case InfoType::IT_default:
147147
return llvm::createStringError(llvm::inconvertibleErrorCode(),
148148
"unexpected info type");
149149
}

clang-tools-extra/clang-doc/Serialize.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ std::string serialize(std::unique_ptr<Info> &I) {
388388
return serialize(*static_cast<EnumInfo *>(I.get()));
389389
case InfoType::IT_function:
390390
return serialize(*static_cast<FunctionInfo *>(I.get()));
391-
default:
391+
case InfoType::IT_typedef:
392+
case InfoType::IT_default:
392393
return "";
393394
}
394395
}
@@ -525,9 +526,13 @@ static std::unique_ptr<Info> makeAndInsertIntoParent(ChildType Child) {
525526
InsertChild(ParentRec->Children, std::forward<ChildType>(Child));
526527
return ParentRec;
527528
}
528-
default:
529-
llvm_unreachable("Invalid reference type for parent namespace");
529+
case InfoType::IT_default:
530+
case InfoType::IT_enum:
531+
case InfoType::IT_function:
532+
case InfoType::IT_typedef:
533+
break;
530534
}
535+
llvm_unreachable("Invalid reference type for parent namespace");
531536
}
532537

533538
// There are two uses for this function.

clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static std::string writeInfo(Info *I) {
3737
return writeInfo(*static_cast<FunctionInfo *>(I));
3838
case InfoType::IT_typedef:
3939
return writeInfo(*static_cast<TypedefInfo *>(I));
40-
default:
40+
case InfoType::IT_default:
4141
return "";
4242
}
4343
}

0 commit comments

Comments
 (0)