Commit 649f5892 by Derek Mauro Committed by Copybara-Service

Deprecate `ABSL_ATTRIBUTE_NORETURN` in favor of the `[[noreturn]]`

standardized in C++11

Migrate all Abseil code to `[[noreturn]]`. Notably,
https://github.com/abseil/abseil-cpp/issues/1698 reports that
`[[noreturn]]` works better here.

We can't migrate `ABSL_ATTRIBUTE_NORETURN` to use `[[noreturn]]`
because the difference in accepted attribute placement
breaks some code.

PiperOrigin-RevId: 648395324
Change-Id: Icd3e9b837aac25f128e8994de099f1edb3cabccf
parent 57f04ad8
...@@ -195,6 +195,9 @@ ...@@ -195,6 +195,9 @@
// ABSL_ATTRIBUTE_NORETURN // ABSL_ATTRIBUTE_NORETURN
// //
// Tells the compiler that a given function never returns. // Tells the compiler that a given function never returns.
//
// Deprecated: Prefer the `[[noreturn]]` attribute standardized by C++11 over
// this macro.
#if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__)) #if ABSL_HAVE_ATTRIBUTE(noreturn) || (defined(__GNUC__) && !defined(__clang__))
#define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn)) #define ABSL_ATTRIBUTE_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
......
...@@ -55,7 +55,7 @@ namespace log_internal { ...@@ -55,7 +55,7 @@ namespace log_internal {
// `line` location. Called when `ABSL_DIE_IF_NULL` fails. Calling this function // `line` location. Called when `ABSL_DIE_IF_NULL` fails. Calling this function
// generates less code than its implementation would if inlined, for a slight // generates less code than its implementation would if inlined, for a slight
// code size reduction each time `ABSL_DIE_IF_NULL` is called. // code size reduction each time `ABSL_DIE_IF_NULL` is called.
ABSL_ATTRIBUTE_NORETURN ABSL_ATTRIBUTE_NOINLINE void DieBecauseNull( [[noreturn]] ABSL_ATTRIBUTE_NOINLINE void DieBecauseNull(
const char* file, int line, const char* exprtext); const char* file, int line, const char* exprtext);
// Helper for `ABSL_DIE_IF_NULL`. // Helper for `ABSL_DIE_IF_NULL`.
......
...@@ -230,8 +230,8 @@ class LogEveryNSecState final { ...@@ -230,8 +230,8 @@ class LogEveryNSecState final {
// Helper routines to abort the application quietly // Helper routines to abort the application quietly
ABSL_ATTRIBUTE_NORETURN inline void AbortQuietly() { abort(); } [[noreturn]] inline void AbortQuietly() { abort(); }
ABSL_ATTRIBUTE_NORETURN inline void ExitQuietly() { _exit(1); } [[noreturn]] inline void ExitQuietly() { _exit(1); }
} // namespace log_internal } // namespace log_internal
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
...@@ -187,11 +187,11 @@ class LogMessage { ...@@ -187,11 +187,11 @@ class LogMessage {
protected: protected:
// Call `abort()` or similar to perform `LOG(FATAL)` crash. It is assumed // Call `abort()` or similar to perform `LOG(FATAL)` crash. It is assumed
// that the caller has already generated and written the trace as appropriate. // that the caller has already generated and written the trace as appropriate.
ABSL_ATTRIBUTE_NORETURN static void FailWithoutStackTrace(); [[noreturn]] static void FailWithoutStackTrace();
// Similar to `FailWithoutStackTrace()`, but without `abort()`. Terminates // Similar to `FailWithoutStackTrace()`, but without `abort()`. Terminates
// the process with an error exit code. // the process with an error exit code.
ABSL_ATTRIBUTE_NORETURN static void FailQuietly(); [[noreturn]] static void FailQuietly();
// Dispatches the completed `absl::LogEntry` to applicable `absl::LogSink`s. // Dispatches the completed `absl::LogEntry` to applicable `absl::LogSink`s.
// This might as well be inlined into `~LogMessage` except that // This might as well be inlined into `~LogMessage` except that
...@@ -354,7 +354,7 @@ class LogMessageFatal final : public LogMessage { ...@@ -354,7 +354,7 @@ class LogMessageFatal final : public LogMessage {
LogMessageFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD; LogMessageFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD;
LogMessageFatal(const char* file, int line, LogMessageFatal(const char* file, int line,
absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD; absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD;
ABSL_ATTRIBUTE_NORETURN ~LogMessageFatal(); [[noreturn]] ~LogMessageFatal();
}; };
// `LogMessageDebugFatal` ensures the process will exit in failure after logging // `LogMessageDebugFatal` ensures the process will exit in failure after logging
...@@ -381,7 +381,7 @@ class LogMessageQuietlyFatal final : public LogMessage { ...@@ -381,7 +381,7 @@ class LogMessageQuietlyFatal final : public LogMessage {
LogMessageQuietlyFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD; LogMessageQuietlyFatal(const char* file, int line) ABSL_ATTRIBUTE_COLD;
LogMessageQuietlyFatal(const char* file, int line, LogMessageQuietlyFatal(const char* file, int line,
absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD; absl::string_view failure_msg) ABSL_ATTRIBUTE_COLD;
ABSL_ATTRIBUTE_NORETURN ~LogMessageQuietlyFatal(); [[noreturn]] ~LogMessageQuietlyFatal();
}; };
} // namespace log_internal } // namespace log_internal
......
...@@ -117,16 +117,7 @@ class NullStreamMaybeFatal final : public NullStream { ...@@ -117,16 +117,7 @@ class NullStreamMaybeFatal final : public NullStream {
class NullStreamFatal final : public NullStream { class NullStreamFatal final : public NullStream {
public: public:
NullStreamFatal() = default; NullStreamFatal() = default;
// ABSL_ATTRIBUTE_NORETURN doesn't seem to work on destructors with msvc, so [[noreturn]] ~NullStreamFatal() { _exit(1); }
// disable msvc's warning about the d'tor never returning.
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning(disable : 4722)
#endif
ABSL_ATTRIBUTE_NORETURN ~NullStreamFatal() { _exit(1); }
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif
}; };
} // namespace log_internal } // namespace log_internal
......
...@@ -186,7 +186,7 @@ class Helper { ...@@ -186,7 +186,7 @@ class Helper {
public: public:
// Move type-agnostic error handling to the .cc. // Move type-agnostic error handling to the .cc.
static void HandleInvalidStatusCtorArg(absl::Nonnull<Status*>); static void HandleInvalidStatusCtorArg(absl::Nonnull<Status*>);
ABSL_ATTRIBUTE_NORETURN static void Crash(const absl::Status& status); [[noreturn]] static void Crash(const absl::Status& status);
}; };
// Construct an instance of T in `p` through placement new, passing Args... to // Construct an instance of T in `p` through placement new, passing Args... to
...@@ -438,7 +438,7 @@ struct MoveAssignBase<T, false> { ...@@ -438,7 +438,7 @@ struct MoveAssignBase<T, false> {
MoveAssignBase& operator=(MoveAssignBase&&) = delete; MoveAssignBase& operator=(MoveAssignBase&&) = delete;
}; };
ABSL_ATTRIBUTE_NORETURN void ThrowBadStatusOrAccess(absl::Status status); [[noreturn]] void ThrowBadStatusOrAccess(absl::Status status);
// Used to introduce jitter into the output of printing functions for // Used to introduce jitter into the output of printing functions for
// `StatusOr` (i.e. `AbslStringify` and `operator<<`). // `StatusOr` (i.e. `AbslStringify` and `operator<<`).
......
...@@ -85,7 +85,7 @@ enum Constants { ...@@ -85,7 +85,7 @@ enum Constants {
}; };
// Emits a fatal error "Unexpected node type: xyz" and aborts the program. // Emits a fatal error "Unexpected node type: xyz" and aborts the program.
ABSL_ATTRIBUTE_NORETURN void LogFatalNodeType(CordRep* rep); [[noreturn]] void LogFatalNodeType(CordRep* rep);
// Fast implementation of memmove for up to 15 bytes. This implementation is // Fast implementation of memmove for up to 15 bytes. This implementation is
// safe for overlapping regions. If nullify_tail is true, the destination is // safe for overlapping regions. If nullify_tail is true, the destination is
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment