From 7f69cd578de899f8b00525a02d1fe25dab567bcf Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 13 Jun 2025 16:35:30 -0700 Subject: [PATCH] [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. --- clang-tools-extra/clang-doc/BitcodeReader.cpp | 4 +--- clang-tools-extra/clang-doc/BitcodeWriter.cpp | 2 +- clang-tools-extra/clang-doc/Representation.cpp | 2 +- clang-tools-extra/clang-doc/Serialize.cpp | 11 ++++++++--- clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp index 57dd514b90a2..35058abab066 100644 --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -54,10 +54,8 @@ static llvm::Error decodeRecord(const Record &R, AccessSpecifier &Field, case AS_none: Field = (AccessSpecifier)R[0]; return llvm::Error::success(); - default: - return llvm::createStringError(llvm::inconvertibleErrorCode(), - "invalid value for AccessSpecifier"); } + llvm_unreachable("invalid value for AccessSpecifier"); } static llvm::Error decodeRecord(const Record &R, TagTypeKind &Field, diff --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp b/clang-tools-extra/clang-doc/BitcodeWriter.cpp index 708ce09d9e5b..f8a6859169b0 100644 --- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp +++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp @@ -664,7 +664,7 @@ bool ClangDocBitcodeWriter::dispatchInfoForWrite(Info *I) { case InfoType::IT_typedef: emitBlock(*static_cast(I)); break; - default: + case InfoType::IT_default: llvm::errs() << "Unexpected info, unable to write.\n"; return true; } diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp index 3ce930c6965d..820d644ef8b8 100644 --- a/clang-tools-extra/clang-doc/Representation.cpp +++ b/clang-tools-extra/clang-doc/Representation.cpp @@ -143,7 +143,7 @@ mergeInfos(std::vector> &Values) { return reduce(Values); case InfoType::IT_typedef: return reduce(Values); - default: + case InfoType::IT_default: return llvm::createStringError(llvm::inconvertibleErrorCode(), "unexpected info type"); } diff --git a/clang-tools-extra/clang-doc/Serialize.cpp b/clang-tools-extra/clang-doc/Serialize.cpp index 3cda38115ff7..e8f1a9cee267 100644 --- a/clang-tools-extra/clang-doc/Serialize.cpp +++ b/clang-tools-extra/clang-doc/Serialize.cpp @@ -388,7 +388,8 @@ std::string serialize(std::unique_ptr &I) { return serialize(*static_cast(I.get())); case InfoType::IT_function: return serialize(*static_cast(I.get())); - default: + case InfoType::IT_typedef: + case InfoType::IT_default: return ""; } } @@ -525,9 +526,13 @@ static std::unique_ptr makeAndInsertIntoParent(ChildType Child) { InsertChild(ParentRec->Children, std::forward(Child)); return ParentRec; } - default: - llvm_unreachable("Invalid reference type for parent namespace"); + case InfoType::IT_default: + case InfoType::IT_enum: + case InfoType::IT_function: + case InfoType::IT_typedef: + break; } + llvm_unreachable("Invalid reference type for parent namespace"); } // There are two uses for this function. diff --git a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp index bbe158ed50e2..659870d2a5c0 100644 --- a/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp +++ b/clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp @@ -37,7 +37,7 @@ static std::string writeInfo(Info *I) { return writeInfo(*static_cast(I)); case InfoType::IT_typedef: return writeInfo(*static_cast(I)); - default: + case InfoType::IT_default: return ""; } }