[libc++] Implement P0627R6 (Function to mark unreachable code)
Reviewed By: ldionne, Quuxplusone, #libc
Spies: arichardson, mstorsjo, libcxx-commits, mgorny
Differential Revision: https://reviews.llvm.org/D119152
NOKEYCHECK=True
GitOrigin-RevId: 2a8f9a5e95dec3adcdee603358dc03def6d2245e
diff --git a/src/filesystem/filesystem_common.h b/src/filesystem/filesystem_common.h
index 99bba27..211b778 100644
--- a/src/filesystem/filesystem_common.h
+++ b/src/filesystem/filesystem_common.h
@@ -14,11 +14,11 @@
#include "chrono"
#include "climits"
#include "cstdarg"
-#include "cstdlib"
#include "ctime"
#include "filesystem"
#include "ratio"
#include "system_error"
+#include <utility>
#if defined(_LIBCPP_WIN32API)
# define WIN32_LEAN_AND_MEAN
@@ -178,7 +178,7 @@
case 2:
__throw_filesystem_error(what, *p1_, *p2_, ec);
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 0)
@@ -197,7 +197,7 @@
case 2:
__throw_filesystem_error(what, *p1_, *p2_, ec);
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
_LIBCPP_ATTRIBUTE_FORMAT(__printf__, 3, 4)
diff --git a/src/filesystem/operations.cpp b/src/filesystem/operations.cpp
index 7aeeffa..244cc98 100644
--- a/src/filesystem/operations.cpp
+++ b/src/filesystem/operations.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include <__utility/unreachable.h>
#include "filesystem"
#include "array"
#include "iterator"
@@ -154,7 +155,7 @@
return makeState(PS_AtEnd);
case PS_AtEnd:
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
}
@@ -202,7 +203,7 @@
return makeState(PS_InRootName, Path.data(), RStart + 1);
case PS_InRootName:
case PS_BeforeBegin:
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
}
@@ -224,7 +225,7 @@
case PS_InFilenames:
return RawEntry;
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
explicit operator bool() const noexcept {
@@ -285,7 +286,7 @@
case PS_AtEnd:
return getAfterBack();
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
/// \brief Return a pointer to the first character in the currently lexed
@@ -302,7 +303,7 @@
case PS_AtEnd:
return &Path.back() + 1;
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
// Consume all consecutive separators.
@@ -681,7 +682,7 @@
return detail::format_string("filesystem error: %s [" PATH_CSTR_FMT "] [" PATH_CSTR_FMT "]",
derived_what, path1().c_str(), path2().c_str());
}
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}();
}
@@ -1188,7 +1189,7 @@
} else if (is_regular_file(st))
return static_cast<uintmax_t>(pst.st_size) == 0;
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
static file_time_type __extract_last_write_time(const path& p, const StatT& st,
@@ -1801,7 +1802,7 @@
break;
}
case PK_None:
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
}
// [fs.path.generic]p6.8: If the path is empty, add a dot.
diff --git a/src/locale.cpp b/src/locale.cpp
index 2234784..56b1a4b 100644
--- a/src/locale.cpp
+++ b/src/locale.cpp
@@ -12,6 +12,7 @@
#define _LCONV_C99
#endif
+#include <__utility/unreachable.h>
#include "algorithm"
#include "clocale"
#include "codecvt"
@@ -4623,7 +4624,7 @@
return false;
#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
diff --git a/src/strstream.cpp b/src/strstream.cpp
index e62c077..fe7e2d4 100644
--- a/src/strstream.cpp
+++ b/src/strstream.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include <__utility/unreachable.h>
#include "strstream"
#include "algorithm"
#include "climits"
@@ -268,7 +269,7 @@
newoff = seekhigh - eback();
break;
default:
- _LIBCPP_UNREACHABLE();
+ __libcpp_unreachable();
}
newoff += __off;
if (0 <= newoff && newoff <= seekhigh - eback())