0
votes

I get the following error when trying to compile the program below. What should be modified to be able to compile? Looks like GCC 4.9.2 can't implement some noexcept move constructors as "=default". The line 7 is causing trouble: TabStats::TabStats(TabStats&& other) noexcept = default;

COMPILATION ERROR: /resource_coordinator/tab_stats.cc:14:1: error: function 'resource_coordinator::TabStats::TabStats(resource_coordinator::TabStats&&)' defaulted on its redeclaration with an exception-specification that differs from the implicit declaration 'resource_coordinator::TabStats::TabStats(resource_coordinator::TabStats&&)' TabStats::TabStats(TabStats&& other) noexcept = default;

^

SOURCE CODE:

#include "browser/resource_coordinator/tab_stats.h"
#include "build/build_config.h"

namespace resource_coordinator {
TabStats::TabStats() = default;
TabStats::TabStats(const TabStats& other) = default;
TabStats::TabStats(TabStats&& other) noexcept = default;
TabStats::~TabStats() {}
TabStats& TabStats::operator=(const TabStats& other) = default;
}  // namespace resource_coordinator

tab_stats.h is included below:

#ifndef BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
#define BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
#include <stdint.h>
#include <vector>
#include "base/process/process.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "build/build_config.h"

namespace content {
class RenderProcessHost;
}  // namespace content

namespace resource_coordinator {

struct TabStats {
  TabStats();
  TabStats(const TabStats& other);
  TabStats(TabStats&& other) noexcept;
  ~TabStats();

  TabStats& operator=(const TabStats& other);

  bool is_app = false;            // Browser window is an app.
  bool is_internal_page = false;  // Internal page, such as NTP or Settings.
  // Playing audio, accessing cam/mic or mirroring display.
  bool is_media = false;
  bool is_pinned = false;
  bool is_in_visible_window = false;
  bool is_in_active_window = false;
  // Whether this is the active tab in a browser window.
  bool is_active = false;
  bool is_discarded = false;
  // User has entered text in a form.
  bool has_form_entry = false;
  int discard_count = 0;
  bool has_beforeunload_handler = false;
  base::TimeTicks last_active;
  base::TimeTicks last_hidden;
  content::RenderProcessHost* render_process_host = nullptr;
  base::ProcessHandle renderer_handle = 0;
  int child_process_host_id = 0;
  base::string16 title;
#if defined(OS_CHROMEOS)
  int oom_score = 0;
#endif
  int64_t tab_contents_id = 0;  // Unique ID per WebContents.
  bool is_auto_discardable = true;
};

typedef std::vector<TabStats> TabStatsList;

}  // namespace resource_coordinator

#endif  // BROWSER_RESOURCE_COORDINATOR_TAB_STATS_H_
1
Probably related: Is the default Move constructor defined as noexcept. So basically you can either not specify noexcept and rely on compiler to implement defaulted constructor or specify noexcept and implement constructor yourself. - user7860670
@VTT can you show me how to implement the construct? I mean... what lines of code I need to fix this?... I have tried different options but still I cant make it compile... - bari
Just write normal move constructor moving all the class fields. Or remove noexcept. - user7860670
@VTT can you write the normal move constructor for this example? I tried many times but I dont know what Im doing wrong... and the no-except specifier cant be removed. The class fields are defined in tab_stats.h (included above) - bari

1 Answers

0
votes

I think, that the problem is that compiler cannot generate default noexcept move constructor because not all of the class members have noexept move constructors.

For example, next code will not compile with the same error:

example::A::A(example::A&&)’ defaulted on its redeclaration with an exception-specification that differs from the implicit exception-specification

namespace example
{
    class B
    {
    public:
        B(B&&);

        int mData;
    };

    B::B(B&&) = default;

    class A
    {
    public:
        A(A&&) noexcept;

        std::string mData;
        B mField;
    };

    A::A(A&&) noexcept = default;
}