0

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_
bari
  • 5
  • 1
  • 4
  • [Probably related: Is the default Move constructor defined as noexcept](https://stackoverflow.com/questions/18653726/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 Oct 31 '17 at 10:11
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Atilla Arda Açıkgöz Oct 31 '17 at 10:19
  • @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 Oct 31 '17 at 18:47
  • Just write normal move constructor moving all the class fields. Or remove `noexcept`. – user7860670 Oct 31 '17 at 18:50
  • @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 Oct 31 '17 at 19:31
  • How come that you've managed to write all this code and don't know how to write a (rather straightforward) constructor? You may want to take a look at [some related question](https://stackoverflow.com/questions/9456910/how-to-define-a-move-constructor). – user7860670 Oct 31 '17 at 19:35
  • @AtillaArdaAçıkgöz I don't see how you can view that as a duplicate. There is no mention of "undefined reference" or "unresolved external symbol" in the error message. – Martin Bonner supports Monica Nov 01 '17 at 11:54
  • @bari: To understand the problem we need a [mcve] because the problem is in the code you aren't showing us. The default move constructor should be noexcept if the move constructor of all its elements is noexcept. Please try and create a sample program with as few members as possible, and with the definitions of all the members shown. Something like https://godbolt.org/g/HYpTe1 (except that compiles fine without errors on gcc 4.9.2). – Martin Bonner supports Monica Nov 01 '17 at 12:03
  • @Martin Bonner This program is part of the chromium source code version 61.0.3163.79. I didnt modify anything, I just copied the code as is... the chromium developers are aware of the compilation bug and they recommend implementing manually the constructor... but the problem is when you dont know to do that (you helped me the other day but now this problem is a bit different from that one and I cant fix it). Here is the link where they say so, and this problem happens not only on android, but also on other linux distros like slax: https://bugs.chromium.org/p/chromium/issues/detail?id=706963 – bari Nov 01 '17 at 12:15
  • @Martin Bonner This program (and the rest of the chromium source code) can be found here (You can find the different releases also): https://chromium.googlesource.com/chromium/src.git/+/61.0.3163.79/chrome/browser/resource_coordinator/tab_stats.cc In order to fix the code, and based on what you showed me before, I Implemented the following constructor to replace line 7, but It looks like there is something wrong and isnt working: TabStats::TabStats(TabStats&& other) noexcept : TimeTicks_(std::move(other.TimeTicks_)), ProcessHandle_ (std::move(other.ProcessHandle_ )) {} – bari Nov 02 '17 at 03:51

1 Answers1

0

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;
}