Re: Non-inline special member functions?
On 6 Okt., 14:03, "Martin B." <0xCDCDC...@gmx.at> wrote:
While investigating some problems [1] with our code I noticed that the
standard
mandates (quoting from [2] N3126, section 12, p254 ff):
[...] An implicitly-declared default constructor is an inline public
member
of its class.
[...] An implicitly declared destructor is an inline public member
of its class.
[...] An implicitly-declared copy[....] constructor is an inline
public
member of its class.
1) Does this actually mean that the compiler is required to inline the
ctor code?
No, an inline specifier is only considered as a non-binding request,
but it has consequences for an implementation nonetheless.
2) Is this over-specified? Why shouldn't an implementation be allowed to
put the
ctor code in a "real" function?
There is nothing that forbids that, but the effects must be the same.
A typical example is the following one:
#include <memory>
class SomeThing {
class Impl; // Not defined here
std::auto_ptr<Impl> pi;
} s;
This program is ill-formed and causes UB (depending on the
actual type Impl), because the inline destructor of SomeThing
will attempt to invoke delete on a pointer to Impl, which is
still an incomplete type at this point.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]