After looking at the code, we had a problem with a copy of elison in the try / catch block. After reading this page:
cpp reference manual and in particular this paragraph:
When handling an exception, if the argument of the catch clause is of the same type (ignoring the top-level cv qualification) as the created exception object, the copy is omitted, and the body of the catch clause gets access to the exception object directly, as if caught by reference
I thought that a copy of elision for the argument to catch would be executed automatically, but one of the reviewers runs a simple test showing that the compiler did not perform these actions:
#include <iostream>
class A
{
public:
A(){}
A(const A&){
std::cout<<"COPY CONSTRUCTOR\n";
}
};
int main()
{
try {
throw A{};
} catch(A a) {
throw a;
}
return 0;
}
When compiling with:
g++ a.cpp -std=c++11 -O3
I got the following output
COPY CONSTRUCTOR
COPY CONSTRUCTOR
terminate called after throwing an instance of 'A'
Aborted (core dumped)
, ( ):
COPY CONSTRUCTOR
terminate called after throwing an instance of 'A'
Aborted (core dumped)
Linux Ubuntu 16.04 g++:
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
?
.