[clang-tools-extra] [clang] [clang][NFC] Refactor `clang::Linkage` (PR #71049)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 05:41:58 PDT 2023


================
@@ -1921,7 +1920,20 @@ bool NamedDecl::declarationReplaces(NamedDecl *OldD, bool IsKnownNewer) const {
 }
 
 bool NamedDecl::hasLinkage() const {
-  return getFormalLinkage() != NoLinkage;
+  switch (getFormalLinkage()) {
+  case Linkage::Invalid:
+    llvm_unreachable("Linkage hasn't been computed!");
+  case Linkage::None:
+    return false;
+  case Linkage::Internal:
+    return true;
+  case Linkage::UniqueExternal:
+  case Linkage::VisibleNone:
+    llvm_unreachable("Non-formal linkage is not allowed here!");
----------------
Endilll wrote:

As I was making sure that `Linkage::Invalid` doesn't creep up where it wasn't before, I converted this to a switch. Then I realized that `UniqueExternal` and `VisibleNone` is not something `getFormalLinkage()` allowed to return, and did a drive-by fix. Since this patch is up for review anyway, I can remove `[NFC]` tag.

https://github.com/llvm/llvm-project/pull/71049


More information about the cfe-commits mailing list