Blob Blame History Raw
From 130a5ae24a02daba8729ba2216bcaf3dbfacea69 Mon Sep 17 00:00:00 2001
From: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Date: Fri, 8 Feb 2019 16:58:38 +0000
Subject: [PATCH] media::learning: Make LabelledExample's move assignment
 operator noexcept
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The GCC build is currently broken with an error like this:

    ../../media/learning/common/labelled_example.cc:20:1: error: function ‘media::learning::LabelledExample::LabelledExample(media::learning::LabelledExample&&)’ defaulted on its redeclaration with an exception-specification that differs from the implicit exception-specification ‘’
     LabelledExample::LabelledExample(LabelledExample&& rhs) noexcept = default;
     ^~~~~~~~~~~~~~~

With GCC, having that noexcept marker requires all members to be marked with
noexcept themselves, and TargetValue was missing some assignment operators
and noexcept markers.

clang is fine because we pass -fno-exceptions and it disables the same error
there, while GCC continues to raise it (bug 843143 and its corresponding CL
have a longer discussion on this issue).

Bug: 819294
Change-Id: Ide30932fc466ccb52d6883a82777e703dae48798
Reviewed-on: https://chromium-review.googlesource.com/c/1458210
Commit-Queue: Frank Liberato <liberato@chromium.org>
Reviewed-by: Frank Liberato <liberato@chromium.org>
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Cr-Commit-Position: refs/heads/master@{#630355}
---
 media/learning/common/labelled_example.cc | 3 ++-
 media/learning/common/labelled_example.h  | 2 +-
 media/learning/common/value.cc            | 6 ++++++
 media/learning/common/value.h             | 4 ++++
 4 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/media/learning/common/labelled_example.cc b/media/learning/common/labelled_example.cc
index 76d08509298e..43e834f9f3cf 100644
--- a/media/learning/common/labelled_example.cc
+++ b/media/learning/common/labelled_example.cc
@@ -59,7 +59,8 @@ bool LabelledExample::operator<(const LabelledExample& rhs) const {
 LabelledExample& LabelledExample::operator=(const LabelledExample& rhs) =
     default;
 
-LabelledExample& LabelledExample::operator=(LabelledExample&& rhs) = default;
+LabelledExample& LabelledExample::operator=(LabelledExample&& rhs) noexcept =
+    default;
 
 TrainingData::TrainingData() = default;
 
diff --git a/media/learning/common/labelled_example.h b/media/learning/common/labelled_example.h
index 4f43c54e7a76..365abc3c0ebf 100644
--- a/media/learning/common/labelled_example.h
+++ b/media/learning/common/labelled_example.h
@@ -40,7 +40,7 @@ struct COMPONENT_EXPORT(LEARNING_COMMON) LabelledExample {
   bool operator<(const LabelledExample& rhs) const;
 
   LabelledExample& operator=(const LabelledExample& rhs);
-  LabelledExample& operator=(LabelledExample&& rhs);
+  LabelledExample& operator=(LabelledExample&& rhs) noexcept;
 
   // Observed feature values.
   // Note that to interpret these values, you probably need to have the
diff --git a/media/learning/common/value.cc b/media/learning/common/value.cc
index 9c9395c25d4e..12ea399d24c3 100644
--- a/media/learning/common/value.cc
+++ b/media/learning/common/value.cc
@@ -23,6 +23,12 @@ Value::Value(const std::string& x) : value_(base::PersistentHash(x)) {}
 
 Value::Value(const Value& other) : value_(other.value_) {}
 
+Value::Value(Value&& rhs) noexcept = default;
+
+Value& Value::operator=(const Value& rhs) = default;
+
+Value& Value::operator=(Value&& rhs) noexcept = default;
+
 bool Value::operator==(const Value& rhs) const {
   return value_ == rhs.value_;
 }
diff --git a/media/learning/common/value.h b/media/learning/common/value.h
index 0e64da961f34..62f4953f691c 100644
--- a/media/learning/common/value.h
+++ b/media/learning/common/value.h
@@ -38,6 +38,10 @@ class COMPONENT_EXPORT(LEARNING_COMMON) Value {
   explicit Value(const std::string& x);
 
   Value(const Value& other);
+  Value(Value&&) noexcept;
+
+  Value& operator=(const Value&);
+  Value& operator=(Value&&) noexcept;
 
   bool operator==(const Value& rhs) const;
   bool operator!=(const Value& rhs) const;
-- 
2.20.1