mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Replace macros with C++17 features (see issue #3362)
- Convert ALLOW_UNUSED_LOCAL to [[maybe_unused]] - Convert WARN_UNUSED_RESULT to [[nodiscard]]
This commit is contained in:
@@ -52,7 +52,6 @@
|
||||
|
||||
#include "include/base/cef_bind.h"
|
||||
#include "include/base/cef_callback.h"
|
||||
#include "include/base/cef_compiler_specific.h"
|
||||
#include "include/base/cef_logging.h"
|
||||
|
||||
namespace base {
|
||||
@@ -184,7 +183,7 @@ class ScopedClosureRunner {
|
||||
void ReplaceClosure(OnceClosure closure);
|
||||
|
||||
// Releases the Closure without calling.
|
||||
OnceClosure Release() WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] OnceClosure Release();
|
||||
|
||||
private:
|
||||
OnceClosure closure_;
|
||||
|
@@ -98,7 +98,6 @@
|
||||
#include "include/base/cef_bind.h"
|
||||
#include "include/base/cef_callback.h"
|
||||
#include "include/base/cef_callback_helpers.h"
|
||||
#include "include/base/cef_compiler_specific.h"
|
||||
#include "include/base/cef_logging.h"
|
||||
#include "include/base/cef_weak_ptr.h"
|
||||
|
||||
@@ -191,7 +190,7 @@ class CallbackListBase {
|
||||
|
||||
// Registers |cb| for future notifications. Returns a CallbackListSubscription
|
||||
// whose destruction will cancel |cb|.
|
||||
CallbackListSubscription Add(CallbackType cb) WARN_UNUSED_RESULT {
|
||||
[[nodiscard]] CallbackListSubscription Add(CallbackType cb) {
|
||||
DCHECK(!cb.is_null());
|
||||
return CallbackListSubscription(base::BindOnce(
|
||||
&CallbackListBase::CancelCallback, weak_ptr_factory_.GetWeakPtr(),
|
||||
|
@@ -386,26 +386,4 @@ inline constexpr bool AnalyzerAssumeTrue(bool arg) {
|
||||
#endif
|
||||
|
||||
#endif // !USING_CHROMIUM_INCLUDES
|
||||
|
||||
// Annotate a function indicating the caller must examine the return value.
|
||||
// Use like:
|
||||
// int foo() WARN_UNUSED_RESULT;
|
||||
// To explicitly ignore a result, use std::ignore from <tuple>.
|
||||
// Alternately use `[[nodiscard]]` with code that supports C++17.
|
||||
#undef WARN_UNUSED_RESULT
|
||||
#if defined(COMPILER_GCC) || defined(__clang__)
|
||||
#define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
|
||||
#else
|
||||
#define WARN_UNUSED_RESULT
|
||||
#endif
|
||||
|
||||
// Annotate a variable indicating it's ok if the variable is not used.
|
||||
// (Typically used to silence a compiler warning when the assignment
|
||||
// is important for some other reason.)
|
||||
// Use like:
|
||||
// int x = ...;
|
||||
// ALLOW_UNUSED_LOCAL(x);
|
||||
// Alternately use `[[maybe_unused]]` with code that supports C++17.
|
||||
#define ALLOW_UNUSED_LOCAL(x) (void)x
|
||||
|
||||
#endif // CEF_INCLUDE_BASE_CEF_COMPILER_SPECIFIC_H_
|
||||
|
@@ -46,7 +46,6 @@
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "include/base/cef_compiler_specific.h"
|
||||
#include "include/base/cef_logging.h"
|
||||
|
||||
template <class T>
|
||||
@@ -289,7 +288,7 @@ class TRIVIAL_ABI scoped_refptr {
|
||||
|
||||
// Returns the owned pointer (if any), releasing ownership to the caller. The
|
||||
// caller is responsible for managing the lifetime of the reference.
|
||||
T* release() WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] T* release();
|
||||
|
||||
void swap(scoped_refptr& r) noexcept { std::swap(ptr_, r.ptr_); }
|
||||
|
||||
|
@@ -74,16 +74,15 @@
|
||||
// If the Chromium implementation diverges the below implementation should be
|
||||
// updated to match.
|
||||
|
||||
#include "include/base/cef_compiler_specific.h"
|
||||
#include "include/base/cef_logging.h"
|
||||
#include "include/base/internal/cef_scoped_policy.h"
|
||||
|
||||
namespace base {
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct ScopedTypeRefTraits;
|
||||
|
||||
template<typename T, typename Traits = ScopedTypeRefTraits<T>>
|
||||
template <typename T, typename Traits = ScopedTypeRefTraits<T>>
|
||||
class ScopedTypeRef {
|
||||
public:
|
||||
using element_type = T;
|
||||
@@ -96,8 +95,7 @@ class ScopedTypeRef {
|
||||
object_ = Traits::Retain(object_);
|
||||
}
|
||||
|
||||
ScopedTypeRef(const ScopedTypeRef<T, Traits>& that)
|
||||
: object_(that.object_) {
|
||||
ScopedTypeRef(const ScopedTypeRef<T, Traits>& that) : object_(that.object_) {
|
||||
if (object_)
|
||||
object_ = Traits::Retain(object_);
|
||||
}
|
||||
@@ -127,7 +125,7 @@ class ScopedTypeRef {
|
||||
// This is to be used only to take ownership of objects that are created
|
||||
// by pass-by-pointer create functions. To enforce this, require that the
|
||||
// object be reset to NULL before this may be used.
|
||||
element_type* InitializeInto() WARN_UNUSED_RESULT {
|
||||
[[nodiscard]] element_type* InitializeInto() {
|
||||
DCHECK(!object_);
|
||||
return &object_;
|
||||
}
|
||||
@@ -163,7 +161,7 @@ class ScopedTypeRef {
|
||||
// ScopedTypeRef<>::release() is like std::unique_ptr<>::release. It is NOT
|
||||
// a wrapper for Release(). To force a ScopedTypeRef<> object to call
|
||||
// Release(), use ScopedTypeRef<>::reset().
|
||||
element_type release() WARN_UNUSED_RESULT {
|
||||
[[nodiscard]] element_type release() {
|
||||
element_type temp = object_;
|
||||
object_ = Traits::InvalidValue();
|
||||
return temp;
|
||||
|
Reference in New Issue
Block a user