On 23.11.2017 11:19, Dirk Zimoch wrote:
Clang 3.4.2 gives an interesting hint with its warnings. It seems that
this call creates a temporary, for which of course a copy is needed. If
you wanted to detect accidental copies, this is such a case.
I have analyzed the code a bit.
The message was:
"C++98 requires an accessible copy constructor for class 'FieldName'
when binding a reference to a temporary"
The line in question is:
pvif(channel->pv->builder->attach(channel->pv->chan, pvf, FieldName()))
This is the constructor call of pvif in the constructor of PDBSinglePut.
It is true, that a temporary is used here. FieldName() creates an object
that falls out of scope immediately after the attach() call.
The compiler cannot know what builder->attach() will do with with the
temporary. It has to expect the worst, which is to keep a reference to
the temporary FieldName object after the attach() call has returned.
Since this would then reference an invalid object.
So maybe the compiler rather implicitly creates a copy of which
builder->attach can keep a reference, like this: attach(new
FieldName(FieldName()))
I need to check the C++ standard to see what the documented behavior is
in such a case.