mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-03-25 16:30:12 +01: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:
parent
02d7a758fe
commit
a9043f2e80
@ -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;
|
||||
|
@ -71,23 +71,23 @@ class CefScopedTempDir {
|
||||
// Creates a unique directory in TempPath, and takes ownership of it.
|
||||
// See file_util::CreateNewTemporaryDirectory.
|
||||
///
|
||||
bool CreateUniqueTempDir() WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] bool CreateUniqueTempDir();
|
||||
|
||||
///
|
||||
// Creates a unique directory under a given path, and takes ownership of it.
|
||||
///
|
||||
bool CreateUniqueTempDirUnderPath(const CefString& path) WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] bool CreateUniqueTempDirUnderPath(const CefString& path);
|
||||
|
||||
///
|
||||
// Takes ownership of directory at |path|, creating it if necessary.
|
||||
// Don't call multiple times unless Take() has been called first.
|
||||
///
|
||||
bool Set(const CefString& path) WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] bool Set(const CefString& path);
|
||||
|
||||
///
|
||||
// Deletes the temporary directory wrapped by this object.
|
||||
///
|
||||
bool Delete() WARN_UNUSED_RESULT;
|
||||
[[nodiscard]] bool Delete();
|
||||
|
||||
///
|
||||
// Caller takes ownership of the temporary directory so it won't be destroyed
|
||||
|
@ -18,8 +18,7 @@ class ScopedGLContext {
|
||||
public:
|
||||
ScopedGLContext(HDC hdc, HGLRC hglrc, bool swap_buffers)
|
||||
: hdc_(hdc), swap_buffers_(swap_buffers) {
|
||||
BOOL result = wglMakeCurrent(hdc, hglrc);
|
||||
ALLOW_UNUSED_LOCAL(result);
|
||||
[[maybe_unused]] BOOL result = wglMakeCurrent(hdc, hglrc);
|
||||
DCHECK(result);
|
||||
}
|
||||
~ScopedGLContext() {
|
||||
@ -188,8 +187,7 @@ void OsrRenderHandlerWinGL::DisableGL() {
|
||||
|
||||
if (IsWindow(hwnd())) {
|
||||
// wglDeleteContext will make the context not current before deleting it.
|
||||
BOOL result = wglDeleteContext(hrc_);
|
||||
ALLOW_UNUSED_LOCAL(result);
|
||||
[[maybe_unused]] BOOL result = wglDeleteContext(hrc_);
|
||||
DCHECK(result);
|
||||
ReleaseDC(hwnd(), hdc_);
|
||||
}
|
||||
|
@ -722,8 +722,7 @@ void RootWindowWin::OnSize(bool minimized) {
|
||||
SWP_NOZORDER);
|
||||
}
|
||||
|
||||
BOOL result = EndDeferWindowPos(hdwp);
|
||||
ALLOW_UNUSED_LOCAL(result);
|
||||
[[maybe_unused]] BOOL result = EndDeferWindowPos(hdwp);
|
||||
DCHECK(result);
|
||||
} else if (browser_window_) {
|
||||
// Size the browser window to the whole client area.
|
||||
@ -1164,9 +1163,8 @@ void UnSubclassWindow(HWND hWnd) {
|
||||
LONG_PTR hParentWndProc =
|
||||
reinterpret_cast<LONG_PTR>(::GetPropW(hWnd, kParentWndProc));
|
||||
if (hParentWndProc) {
|
||||
LONG_PTR hPreviousWndProc =
|
||||
[[maybe_unused]] LONG_PTR hPreviousWndProc =
|
||||
SetWindowLongPtr(hWnd, GWLP_WNDPROC, hParentWndProc);
|
||||
ALLOW_UNUSED_LOCAL(hPreviousWndProc);
|
||||
DCHECK_EQ(hPreviousWndProc,
|
||||
reinterpret_cast<LONG_PTR>(SubclassedWindowProc));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user