Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Use the standard [[nodiscard]] attribute instead of an FML macro. #17100

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions assets/asset_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class AssetResolver {

virtual bool IsValid() const = 0;

FML_WARN_UNUSED_RESULT
virtual std::unique_ptr<fml::Mapping> GetAsMapping(
[[nodiscard]] virtual std::unique_ptr<fml::Mapping> GetAsMapping(
const std::string& asset_name) const = 0;

private:
Expand Down
11 changes: 5 additions & 6 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Layer {
// destruction.
class AutoPrerollSaveLayerState {
public:
FML_WARN_UNUSED_RESULT static AutoPrerollSaveLayerState Create(
[[nodiscard]] static AutoPrerollSaveLayerState Create(
PrerollContext* preroll_context,
bool save_layer_is_active = true,
bool layer_itself_performs_readback = false);
Expand Down Expand Up @@ -133,12 +133,11 @@ class Layer {
// draws a checkerboard over the layer if that is enabled in the PaintContext.
class AutoSaveLayer {
public:
FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint);
[[nodiscard]] static AutoSaveLayer Create(const PaintContext& paint_context,
const SkRect& bounds,
const SkPaint* paint);

FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
[[nodiscard]] static AutoSaveLayer Create(
const PaintContext& paint_context,
const SkCanvas::SaveLayerRec& layer_rec);

Expand Down
5 changes: 2 additions & 3 deletions flow/scene_update_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ class SceneUpdateContext {
// CPU wait. Once Vulkan semaphores are available, this method must return
// void and the implementation must submit surfaces on its own as soon as the
// specific canvas operations are done.
FML_WARN_UNUSED_RESULT
std::vector<std::unique_ptr<SurfaceProducerSurface>> ExecutePaintTasks(
CompositorContext::ScopedFrame& frame);
[[nodiscard]] std::vector<std::unique_ptr<SurfaceProducerSurface>>
ExecutePaintTasks(CompositorContext::ScopedFrame& frame);

float ScaleX() const { return metrics_->scale_x * top_scale_x_; }
float ScaleY() const { return metrics_->scale_y * top_scale_y_; }
Expand Down
10 changes: 0 additions & 10 deletions fml/compiler_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,6 @@
#define FML_ALIGNOF(type) __alignof(type)
#endif

// Annotate a function indicating the caller must examine the return value.
// Use like:
// int foo() FML_WARN_UNUSED_RESULT;
// To explicitly ignore a result, see |ignore_result()| in base/macros.h.
#if defined(__GNUC__) || defined(__clang__)
#define FML_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define FML_WARN_UNUSED_RESULT
#endif

// Tell the compiler a function is using a printf-style format string.
// |format_param| is the one-based index of the format string parameter;
// |dots_param| is the one-based index of the "..." parameter.
Expand Down
24 changes: 10 additions & 14 deletions fml/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ class Message {

template <typename T,
typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
FML_WARN_UNUSED_RESULT bool Encode(const T& value) {
[[nodiscard]] bool Encode(const T& value) {
if (auto* buffer = PrepareEncode(sizeof(T))) {
::memcpy(buffer, &value, sizeof(T));
return true;
}
return false;
}

FML_WARN_UNUSED_RESULT bool Encode(const MessageSerializable& value) {
[[nodiscard]] bool Encode(const MessageSerializable& value) {
return value.Serialize(*this);
}

template <typename Traits,
typename T,
typename = std::enable_if_t<
std::is_base_of<MessageSerializable, T>::value>>
FML_WARN_UNUSED_RESULT bool Encode(const std::unique_ptr<T>& value) {
[[nodiscard]] bool Encode(const std::unique_ptr<T>& value) {
// Encode if null.
if (!Encode(static_cast<bool>(value))) {
return false;
Expand All @@ -130,23 +130,23 @@ class Message {

template <typename T,
typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
FML_WARN_UNUSED_RESULT bool Decode(T& value) {
[[nodiscard]] bool Decode(T& value) {
if (auto* buffer = PrepareDecode(sizeof(T))) {
::memcpy(&value, buffer, sizeof(T));
return true;
}
return false;
}

FML_WARN_UNUSED_RESULT bool Decode(MessageSerializable& value) {
[[nodiscard]] bool Decode(MessageSerializable& value) {
return value.Deserialize(*this);
}

template <typename Traits,
typename T,
typename = std::enable_if_t<
std::is_base_of<MessageSerializable, T>::value>>
FML_WARN_UNUSED_RESULT bool Decode(std::unique_ptr<T>& value) {
[[nodiscard]] bool Decode(std::unique_ptr<T>& value) {
// Decode if null.
bool is_null = false;
if (!Decode(is_null)) {
Expand Down Expand Up @@ -184,17 +184,13 @@ class Message {
size_t data_length_ = 0;
size_t size_read_ = 0;

FML_WARN_UNUSED_RESULT
bool Reserve(size_t size);
[[nodiscard]] bool Reserve(size_t size);

FML_WARN_UNUSED_RESULT
bool Resize(size_t size);
[[nodiscard]] bool Resize(size_t size);

FML_WARN_UNUSED_RESULT
uint8_t* PrepareEncode(size_t size);
[[nodiscard]] uint8_t* PrepareEncode(size_t size);

FML_WARN_UNUSED_RESULT
uint8_t* PrepareDecode(size_t size);
[[nodiscard]] uint8_t* PrepareDecode(size_t size);

FML_DISALLOW_COPY_AND_ASSIGN(Message);
};
Expand Down
2 changes: 1 addition & 1 deletion fml/platform/darwin/scoped_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ScopedBlock {
block_ = temp;
}

B release() FML_WARN_UNUSED_RESULT {
[[nodiscard]] B release() {
B temp = block_;
block_ = nullptr;
return temp;
Expand Down
2 changes: 1 addition & 1 deletion fml/platform/darwin/scoped_nsobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class scoped_nsprotocol {
// scoped_nsprotocol<>::release() is like scoped_ptr<>::release. It is NOT a
// wrapper for [object_ release]. To force a scoped_nsprotocol<> to call
// [object_ release], use scoped_nsprotocol<>::reset().
NST release() FML_WARN_UNUSED_RESULT {
[[nodiscard]] NST release() {
NST temp = object_;
object_ = nil;
return temp;
Expand Down
3 changes: 1 addition & 2 deletions fml/synchronization/semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Semaphore {

bool IsValid() const;

FML_WARN_UNUSED_RESULT
bool TryWait();
[[nodiscard]] bool TryWait();

void Signal();

Expand Down
2 changes: 1 addition & 1 deletion fml/unique_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class UniqueObject {
// Release the object. The return value is the current object held by this
// object. After this operation, this object will hold an invalid value, and
// will not own the object any more.
T release() FML_WARN_UNUSED_RESULT {
[[nodiscard]] T release() {
T old_generic = data_.generic;
data_.generic = Traits::InvalidValue();
return old_generic;
Expand Down
32 changes: 14 additions & 18 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
return true;
}

FML_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromKernel(
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernel(
std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
TRACE_EVENT0("flutter", "DartIsolate::PrepareForRunningFromKernel");
Expand Down Expand Up @@ -405,8 +404,7 @@ bool DartIsolate::PrepareForRunningFromKernel(
return true;
}

FML_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromKernels(
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernels(
std::vector<std::shared_ptr<const fml::Mapping>> kernels) {
const auto count = kernels.size();
if (count == 0) {
Expand All @@ -423,8 +421,7 @@ bool DartIsolate::PrepareForRunningFromKernels(
return true;
}

FML_WARN_UNUSED_RESULT
bool DartIsolate::PrepareForRunningFromKernels(
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernels(
std::vector<std::unique_ptr<const fml::Mapping>> kernels) {
std::vector<std::shared_ptr<const fml::Mapping>> shared_kernels;
for (auto& kernel : kernels) {
Expand Down Expand Up @@ -460,9 +457,9 @@ bool DartIsolate::MarkIsolateRunnable() {
return true;
}

FML_WARN_UNUSED_RESULT
static bool InvokeMainEntrypoint(Dart_Handle user_entrypoint_function,
Dart_Handle args) {
[[nodiscard]] static bool InvokeMainEntrypoint(
Dart_Handle user_entrypoint_function,
Dart_Handle args) {
if (tonic::LogIfError(user_entrypoint_function)) {
FML_LOG(ERROR) << "Could not resolve main entrypoint function.";
return false;
Expand All @@ -488,10 +485,9 @@ static bool InvokeMainEntrypoint(Dart_Handle user_entrypoint_function,
}

/// @note Procedure doesn't copy all closures.
FML_WARN_UNUSED_RESULT
bool DartIsolate::Run(const std::string& entrypoint_name,
const std::vector<std::string>& args,
const fml::closure& on_run) {
[[nodiscard]] bool DartIsolate::Run(const std::string& entrypoint_name,
const std::vector<std::string>& args,
const fml::closure& on_run) {
TRACE_EVENT0("flutter", "DartIsolate::Run");
if (phase_ != Phase::Ready) {
return false;
Expand All @@ -517,11 +513,11 @@ bool DartIsolate::Run(const std::string& entrypoint_name,
}

/// @note Procedure doesn't copy all closures.
FML_WARN_UNUSED_RESULT
bool DartIsolate::RunFromLibrary(const std::string& library_name,
const std::string& entrypoint_name,
const std::vector<std::string>& args,
const fml::closure& on_run) {
[[nodiscard]] bool DartIsolate::RunFromLibrary(
const std::string& library_name,
const std::string& entrypoint_name,
const std::vector<std::string>& args,
const fml::closure& on_run) {
TRACE_EVENT0("flutter", "DartIsolate::RunFromLibrary");
if (phase_ != Phase::Ready) {
return false;
Expand Down
42 changes: 17 additions & 25 deletions runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ class DartIsolate : public UIDartState {
/// @return Whether the isolate was prepared and the described phase
/// transition made.
///
FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromPrecompiledCode();
[[nodiscard]] bool PrepareForRunningFromPrecompiledCode();

//----------------------------------------------------------------------------
/// @brief Prepare the isolate for running for a a list of kernel files.
Expand All @@ -265,9 +264,9 @@ class DartIsolate : public UIDartState {
/// @return If the kernel mapping supplied was successfully used to
/// prepare the isolate.
///
FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromKernel(std::shared_ptr<const fml::Mapping> kernel,
bool last_piece = true);
[[nodiscard]] bool PrepareForRunningFromKernel(
std::shared_ptr<const fml::Mapping> kernel,
bool last_piece = true);

//----------------------------------------------------------------------------
/// @brief Prepare the isolate for running for a a list of kernel files.
Expand All @@ -284,8 +283,7 @@ class DartIsolate : public UIDartState {
/// @return If the kernel mappings supplied were successfully used to
/// prepare the isolate.
///
FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromKernels(
[[nodiscard]] bool PrepareForRunningFromKernels(
std::vector<std::shared_ptr<const fml::Mapping>> kernels);

//----------------------------------------------------------------------------
Expand All @@ -303,8 +301,7 @@ class DartIsolate : public UIDartState {
/// @return If the kernel mappings supplied were successfully used to
/// prepare the isolate.
///
FML_WARN_UNUSED_RESULT
bool PrepareForRunningFromKernels(
[[nodiscard]] bool PrepareForRunningFromKernels(
std::vector<std::unique_ptr<const fml::Mapping>> kernels);

//----------------------------------------------------------------------------
Expand All @@ -323,10 +320,9 @@ class DartIsolate : public UIDartState {
/// @return If the isolate successfully transitioned to the running phase
/// and the main entrypoint was invoked.
///
FML_WARN_UNUSED_RESULT
bool Run(const std::string& entrypoint,
const std::vector<std::string>& args,
const fml::closure& on_run = nullptr);
[[nodiscard]] bool Run(const std::string& entrypoint,
const std::vector<std::string>& args,
const fml::closure& on_run = nullptr);

//----------------------------------------------------------------------------
/// @brief Transition the root isolate to the `Phase::Running` phase and
Expand All @@ -346,20 +342,18 @@ class DartIsolate : public UIDartState {
/// @return If the isolate successfully transitioned to the running phase
/// and the main entrypoint was invoked.
///
FML_WARN_UNUSED_RESULT
bool RunFromLibrary(const std::string& library_name,
const std::string& entrypoint,
const std::vector<std::string>& args,
const fml::closure& on_run = nullptr);
[[nodiscard]] bool RunFromLibrary(const std::string& library_name,
const std::string& entrypoint,
const std::vector<std::string>& args,
const fml::closure& on_run = nullptr);

//----------------------------------------------------------------------------
/// @brief Transition the isolate to the `Phase::Shutdown` phase. The
/// only thing left to do is to collect the isolate.
///
/// @return If the isolate succesfully transitioned to the shutdown phase.
///
FML_WARN_UNUSED_RESULT
bool Shutdown();
[[nodiscard]] bool Shutdown();

//----------------------------------------------------------------------------
/// @brief Registers a callback that will be invoked in isolate scope
Expand Down Expand Up @@ -418,19 +412,17 @@ class DartIsolate : public UIDartState {
std::string advisory_script_uri,
std::string advisory_script_entrypoint,
bool is_root_isolate);
FML_WARN_UNUSED_RESULT bool Initialize(Dart_Isolate isolate);
[[nodiscard]] bool Initialize(Dart_Isolate isolate);

void SetMessageHandlingTaskRunner(fml::RefPtr<fml::TaskRunner> runner);

bool LoadKernel(std::shared_ptr<const fml::Mapping> mapping, bool last_piece);

FML_WARN_UNUSED_RESULT
bool LoadLibraries();
[[nodiscard]] bool LoadLibraries();

bool UpdateThreadPoolNames() const;

FML_WARN_UNUSED_RESULT
bool MarkIsolateRunnable();
[[nodiscard]] bool MarkIsolateRunnable();

void OnShutdownCallback();

Expand Down
3 changes: 1 addition & 2 deletions runtime/dart_service_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ class DartServiceIsolate {

// Returns a handle for the callback that can be used in
// RemoveServerStatusCallback
FML_WARN_UNUSED_RESULT
static CallbackHandle AddServerStatusCallback(
[[nodiscard]] static CallbackHandle AddServerStatusCallback(
const ObservatoryServerStateCallback& callback);

// Accepts the handle returned by AddServerStatusCallback
Expand Down
8 changes: 4 additions & 4 deletions runtime/dart_vm_lifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace flutter {
// DartVMRef instances may be created on any thread.
class DartVMRef {
public:
FML_WARN_UNUSED_RESULT
static DartVMRef Create(Settings settings,
fml::RefPtr<DartSnapshot> vm_snapshot = nullptr,
fml::RefPtr<DartSnapshot> isolate_snapshot = nullptr);
[[nodiscard]] static DartVMRef Create(
Settings settings,
fml::RefPtr<DartSnapshot> vm_snapshot = nullptr,
fml::RefPtr<DartSnapshot> isolate_snapshot = nullptr);

DartVMRef(DartVMRef&&);

Expand Down
3 changes: 1 addition & 2 deletions runtime/service_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ bool ServiceProtocol::HandleMessage(std::string_view method,
return service_protocol->HandleMessage(method, params, response);
}

FML_WARN_UNUSED_RESULT
static bool HandleMessageOnHandler(
[[nodiscard]] static bool HandleMessageOnHandler(
ServiceProtocol::Handler* handler,
std::string_view method,
const ServiceProtocol::Handler::ServiceProtocolMap& params,
Expand Down
Loading