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

Commit a37560a

Browse files
authored
Use the standard [[nodiscard]] attribute instead of an FML macro. (#17100)
1 parent 8c8b3e1 commit a37560a

25 files changed

+112
-162
lines changed

assets/asset_resolver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class AssetResolver {
2121

2222
virtual bool IsValid() const = 0;
2323

24-
FML_WARN_UNUSED_RESULT
25-
virtual std::unique_ptr<fml::Mapping> GetAsMapping(
24+
[[nodiscard]] virtual std::unique_ptr<fml::Mapping> GetAsMapping(
2625
const std::string& asset_name) const = 0;
2726

2827
private:

flow/layers/layer.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Layer {
8484
// destruction.
8585
class AutoPrerollSaveLayerState {
8686
public:
87-
FML_WARN_UNUSED_RESULT static AutoPrerollSaveLayerState Create(
87+
[[nodiscard]] static AutoPrerollSaveLayerState Create(
8888
PrerollContext* preroll_context,
8989
bool save_layer_is_active = true,
9090
bool layer_itself_performs_readback = false);
@@ -133,12 +133,11 @@ class Layer {
133133
// draws a checkerboard over the layer if that is enabled in the PaintContext.
134134
class AutoSaveLayer {
135135
public:
136-
FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
137-
const PaintContext& paint_context,
138-
const SkRect& bounds,
139-
const SkPaint* paint);
136+
[[nodiscard]] static AutoSaveLayer Create(const PaintContext& paint_context,
137+
const SkRect& bounds,
138+
const SkPaint* paint);
140139

141-
FML_WARN_UNUSED_RESULT static AutoSaveLayer Create(
140+
[[nodiscard]] static AutoSaveLayer Create(
142141
const PaintContext& paint_context,
143142
const SkCanvas::SaveLayerRec& layer_rec);
144143

flow/scene_update_context.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ class SceneUpdateContext {
162162
// CPU wait. Once Vulkan semaphores are available, this method must return
163163
// void and the implementation must submit surfaces on its own as soon as the
164164
// specific canvas operations are done.
165-
FML_WARN_UNUSED_RESULT
166-
std::vector<std::unique_ptr<SurfaceProducerSurface>> ExecutePaintTasks(
167-
CompositorContext::ScopedFrame& frame);
165+
[[nodiscard]] std::vector<std::unique_ptr<SurfaceProducerSurface>>
166+
ExecutePaintTasks(CompositorContext::ScopedFrame& frame);
168167

169168
float ScaleX() const { return metrics_->scale_x * top_scale_x_; }
170169
float ScaleY() const { return metrics_->scale_y * top_scale_y_; }

fml/compiler_specific.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,6 @@
5454
#define FML_ALIGNOF(type) __alignof(type)
5555
#endif
5656

57-
// Annotate a function indicating the caller must examine the return value.
58-
// Use like:
59-
// int foo() FML_WARN_UNUSED_RESULT;
60-
// To explicitly ignore a result, see |ignore_result()| in base/macros.h.
61-
#if defined(__GNUC__) || defined(__clang__)
62-
#define FML_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
63-
#else
64-
#define FML_WARN_UNUSED_RESULT
65-
#endif
66-
6757
// Tell the compiler a function is using a printf-style format string.
6858
// |format_param| is the one-based index of the format string parameter;
6959
// |dots_param| is the one-based index of the "..." parameter.

fml/message.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ class Message {
8787

8888
template <typename T,
8989
typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
90-
FML_WARN_UNUSED_RESULT bool Encode(const T& value) {
90+
[[nodiscard]] bool Encode(const T& value) {
9191
if (auto* buffer = PrepareEncode(sizeof(T))) {
9292
::memcpy(buffer, &value, sizeof(T));
9393
return true;
9494
}
9595
return false;
9696
}
9797

98-
FML_WARN_UNUSED_RESULT bool Encode(const MessageSerializable& value) {
98+
[[nodiscard]] bool Encode(const MessageSerializable& value) {
9999
return value.Serialize(*this);
100100
}
101101

102102
template <typename Traits,
103103
typename T,
104104
typename = std::enable_if_t<
105105
std::is_base_of<MessageSerializable, T>::value>>
106-
FML_WARN_UNUSED_RESULT bool Encode(const std::unique_ptr<T>& value) {
106+
[[nodiscard]] bool Encode(const std::unique_ptr<T>& value) {
107107
// Encode if null.
108108
if (!Encode(static_cast<bool>(value))) {
109109
return false;
@@ -130,23 +130,23 @@ class Message {
130130

131131
template <typename T,
132132
typename = std::enable_if_t<std::is_trivially_copyable<T>::value>>
133-
FML_WARN_UNUSED_RESULT bool Decode(T& value) {
133+
[[nodiscard]] bool Decode(T& value) {
134134
if (auto* buffer = PrepareDecode(sizeof(T))) {
135135
::memcpy(&value, buffer, sizeof(T));
136136
return true;
137137
}
138138
return false;
139139
}
140140

141-
FML_WARN_UNUSED_RESULT bool Decode(MessageSerializable& value) {
141+
[[nodiscard]] bool Decode(MessageSerializable& value) {
142142
return value.Deserialize(*this);
143143
}
144144

145145
template <typename Traits,
146146
typename T,
147147
typename = std::enable_if_t<
148148
std::is_base_of<MessageSerializable, T>::value>>
149-
FML_WARN_UNUSED_RESULT bool Decode(std::unique_ptr<T>& value) {
149+
[[nodiscard]] bool Decode(std::unique_ptr<T>& value) {
150150
// Decode if null.
151151
bool is_null = false;
152152
if (!Decode(is_null)) {
@@ -184,17 +184,13 @@ class Message {
184184
size_t data_length_ = 0;
185185
size_t size_read_ = 0;
186186

187-
FML_WARN_UNUSED_RESULT
188-
bool Reserve(size_t size);
187+
[[nodiscard]] bool Reserve(size_t size);
189188

190-
FML_WARN_UNUSED_RESULT
191-
bool Resize(size_t size);
189+
[[nodiscard]] bool Resize(size_t size);
192190

193-
FML_WARN_UNUSED_RESULT
194-
uint8_t* PrepareEncode(size_t size);
191+
[[nodiscard]] uint8_t* PrepareEncode(size_t size);
195192

196-
FML_WARN_UNUSED_RESULT
197-
uint8_t* PrepareDecode(size_t size);
193+
[[nodiscard]] uint8_t* PrepareDecode(size_t size);
198194

199195
FML_DISALLOW_COPY_AND_ASSIGN(Message);
200196
};

fml/platform/darwin/scoped_block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ScopedBlock {
7272
block_ = temp;
7373
}
7474

75-
B release() FML_WARN_UNUSED_RESULT {
75+
[[nodiscard]] B release() {
7676
B temp = block_;
7777
block_ = nullptr;
7878
return temp;

fml/platform/darwin/scoped_nsobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class scoped_nsprotocol {
7979
// scoped_nsprotocol<>::release() is like scoped_ptr<>::release. It is NOT a
8080
// wrapper for [object_ release]. To force a scoped_nsprotocol<> to call
8181
// [object_ release], use scoped_nsprotocol<>::reset().
82-
NST release() FML_WARN_UNUSED_RESULT {
82+
[[nodiscard]] NST release() {
8383
NST temp = object_;
8484
object_ = nil;
8585
return temp;

fml/synchronization/semaphore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class Semaphore {
2222

2323
bool IsValid() const;
2424

25-
FML_WARN_UNUSED_RESULT
26-
bool TryWait();
25+
[[nodiscard]] bool TryWait();
2726

2827
void Signal();
2928

fml/unique_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class UniqueObject {
7878
// Release the object. The return value is the current object held by this
7979
// object. After this operation, this object will hold an invalid value, and
8080
// will not own the object any more.
81-
T release() FML_WARN_UNUSED_RESULT {
81+
[[nodiscard]] T release() {
8282
T old_generic = data_.generic;
8383
data_.generic = Traits::InvalidValue();
8484
return old_generic;

runtime/dart_isolate.cc

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
338338
return true;
339339
}
340340

341-
FML_WARN_UNUSED_RESULT
342-
bool DartIsolate::PrepareForRunningFromKernel(
341+
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernel(
343342
std::shared_ptr<const fml::Mapping> mapping,
344343
bool last_piece) {
345344
TRACE_EVENT0("flutter", "DartIsolate::PrepareForRunningFromKernel");
@@ -405,8 +404,7 @@ bool DartIsolate::PrepareForRunningFromKernel(
405404
return true;
406405
}
407406

408-
FML_WARN_UNUSED_RESULT
409-
bool DartIsolate::PrepareForRunningFromKernels(
407+
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernels(
410408
std::vector<std::shared_ptr<const fml::Mapping>> kernels) {
411409
const auto count = kernels.size();
412410
if (count == 0) {
@@ -423,8 +421,7 @@ bool DartIsolate::PrepareForRunningFromKernels(
423421
return true;
424422
}
425423

426-
FML_WARN_UNUSED_RESULT
427-
bool DartIsolate::PrepareForRunningFromKernels(
424+
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernels(
428425
std::vector<std::unique_ptr<const fml::Mapping>> kernels) {
429426
std::vector<std::shared_ptr<const fml::Mapping>> shared_kernels;
430427
for (auto& kernel : kernels) {
@@ -460,9 +457,9 @@ bool DartIsolate::MarkIsolateRunnable() {
460457
return true;
461458
}
462459

463-
FML_WARN_UNUSED_RESULT
464-
static bool InvokeMainEntrypoint(Dart_Handle user_entrypoint_function,
465-
Dart_Handle args) {
460+
[[nodiscard]] static bool InvokeMainEntrypoint(
461+
Dart_Handle user_entrypoint_function,
462+
Dart_Handle args) {
466463
if (tonic::LogIfError(user_entrypoint_function)) {
467464
FML_LOG(ERROR) << "Could not resolve main entrypoint function.";
468465
return false;
@@ -488,10 +485,9 @@ static bool InvokeMainEntrypoint(Dart_Handle user_entrypoint_function,
488485
}
489486

490487
/// @note Procedure doesn't copy all closures.
491-
FML_WARN_UNUSED_RESULT
492-
bool DartIsolate::Run(const std::string& entrypoint_name,
493-
const std::vector<std::string>& args,
494-
const fml::closure& on_run) {
488+
[[nodiscard]] bool DartIsolate::Run(const std::string& entrypoint_name,
489+
const std::vector<std::string>& args,
490+
const fml::closure& on_run) {
495491
TRACE_EVENT0("flutter", "DartIsolate::Run");
496492
if (phase_ != Phase::Ready) {
497493
return false;
@@ -517,11 +513,11 @@ bool DartIsolate::Run(const std::string& entrypoint_name,
517513
}
518514

519515
/// @note Procedure doesn't copy all closures.
520-
FML_WARN_UNUSED_RESULT
521-
bool DartIsolate::RunFromLibrary(const std::string& library_name,
522-
const std::string& entrypoint_name,
523-
const std::vector<std::string>& args,
524-
const fml::closure& on_run) {
516+
[[nodiscard]] bool DartIsolate::RunFromLibrary(
517+
const std::string& library_name,
518+
const std::string& entrypoint_name,
519+
const std::vector<std::string>& args,
520+
const fml::closure& on_run) {
525521
TRACE_EVENT0("flutter", "DartIsolate::RunFromLibrary");
526522
if (phase_ != Phase::Ready) {
527523
return false;

runtime/dart_isolate.h

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,7 @@ class DartIsolate : public UIDartState {
241241
/// @return Whether the isolate was prepared and the described phase
242242
/// transition made.
243243
///
244-
FML_WARN_UNUSED_RESULT
245-
bool PrepareForRunningFromPrecompiledCode();
244+
[[nodiscard]] bool PrepareForRunningFromPrecompiledCode();
246245

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

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

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

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

331327
//----------------------------------------------------------------------------
332328
/// @brief Transition the root isolate to the `Phase::Running` phase and
@@ -346,20 +342,18 @@ class DartIsolate : public UIDartState {
346342
/// @return If the isolate successfully transitioned to the running phase
347343
/// and the main entrypoint was invoked.
348344
///
349-
FML_WARN_UNUSED_RESULT
350-
bool RunFromLibrary(const std::string& library_name,
351-
const std::string& entrypoint,
352-
const std::vector<std::string>& args,
353-
const fml::closure& on_run = nullptr);
345+
[[nodiscard]] bool RunFromLibrary(const std::string& library_name,
346+
const std::string& entrypoint,
347+
const std::vector<std::string>& args,
348+
const fml::closure& on_run = nullptr);
354349

355350
//----------------------------------------------------------------------------
356351
/// @brief Transition the isolate to the `Phase::Shutdown` phase. The
357352
/// only thing left to do is to collect the isolate.
358353
///
359354
/// @return If the isolate succesfully transitioned to the shutdown phase.
360355
///
361-
FML_WARN_UNUSED_RESULT
362-
bool Shutdown();
356+
[[nodiscard]] bool Shutdown();
363357

364358
//----------------------------------------------------------------------------
365359
/// @brief Registers a callback that will be invoked in isolate scope
@@ -418,19 +412,17 @@ class DartIsolate : public UIDartState {
418412
std::string advisory_script_uri,
419413
std::string advisory_script_entrypoint,
420414
bool is_root_isolate);
421-
FML_WARN_UNUSED_RESULT bool Initialize(Dart_Isolate isolate);
415+
[[nodiscard]] bool Initialize(Dart_Isolate isolate);
422416

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

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

427-
FML_WARN_UNUSED_RESULT
428-
bool LoadLibraries();
421+
[[nodiscard]] bool LoadLibraries();
429422

430423
bool UpdateThreadPoolNames() const;
431424

432-
FML_WARN_UNUSED_RESULT
433-
bool MarkIsolateRunnable();
425+
[[nodiscard]] bool MarkIsolateRunnable();
434426

435427
void OnShutdownCallback();
436428

runtime/dart_service_isolate.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class DartServiceIsolate {
3333

3434
// Returns a handle for the callback that can be used in
3535
// RemoveServerStatusCallback
36-
FML_WARN_UNUSED_RESULT
37-
static CallbackHandle AddServerStatusCallback(
36+
[[nodiscard]] static CallbackHandle AddServerStatusCallback(
3837
const ObservatoryServerStateCallback& callback);
3938

4039
// Accepts the handle returned by AddServerStatusCallback

runtime/dart_vm_lifecycle.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ namespace flutter {
2626
// DartVMRef instances may be created on any thread.
2727
class DartVMRef {
2828
public:
29-
FML_WARN_UNUSED_RESULT
30-
static DartVMRef Create(Settings settings,
31-
fml::RefPtr<DartSnapshot> vm_snapshot = nullptr,
32-
fml::RefPtr<DartSnapshot> isolate_snapshot = nullptr);
29+
[[nodiscard]] static DartVMRef Create(
30+
Settings settings,
31+
fml::RefPtr<DartSnapshot> vm_snapshot = nullptr,
32+
fml::RefPtr<DartSnapshot> isolate_snapshot = nullptr);
3333

3434
DartVMRef(DartVMRef&&);
3535

runtime/service_protocol.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ bool ServiceProtocol::HandleMessage(std::string_view method,
146146
return service_protocol->HandleMessage(method, params, response);
147147
}
148148

149-
FML_WARN_UNUSED_RESULT
150-
static bool HandleMessageOnHandler(
149+
[[nodiscard]] static bool HandleMessageOnHandler(
151150
ServiceProtocol::Handler* handler,
152151
std::string_view method,
153152
const ServiceProtocol::Handler::ServiceProtocolMap& params,

0 commit comments

Comments
 (0)