[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: implicit declarations
From: |
Felix Salfelder |
Subject: |
Re: implicit declarations |
Date: |
Sun, 20 Sep 2020 09:13:18 +0200 |
On Sat, Sep 19, 2020 at 10:17:09PM -0400, al davis wrote:
> Starting with C++11, there is an explicit way to specify this ...
> using a generated constructor, disabling a constructor.
I think you are referring to
class C{
public:
C(C const&) = default;
[..]
};
> I think it is time to switch over to the new way, supported
> by compilers since c++11, everywhere, and start requiring c++11 or c++14
> or later.
Don't know. I can think of two downsides.
- There is no space for test hooks in a constructor specified "default".
this breaks keeping track of testing the way we do it.
- It seems to be a lot of typing and testing for no actual benefit in
return.
> Some systems still in common use do not yet support c++17, so I think
> c++14 is appropriate now.
tldr, yes. Require c++14 and use it when touching the code (e.g. when
editing for some other reason). A few warnings will show up when setting
-std=c++14.
There are other language features from c++-11 worth considering. None I
feel strong about, nor would I recommend immediate switching.
Instead of
private:
C(C const&) { unreachable(); }
we could write
C(...) = delete; // no problem here with test hook.
private: // if needed
And second, there is an override decorator. "In a member function
declaration or definition, override specifier ensures that the function
is virtual and is overriding a virtual function from a base class. The
program is ill-formed (a compile-time error is generated) if this is not
true."
(Currently, there are section headers / comments in the code that
indicate overrides.)
cheers
felix