Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Daniel Krügler <daniel.kruegler@googlemail.com> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Defect report: abstract final classes |
| Date | 2011-12-01 13:05 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <jb89ot$bnd$1@dont-email.me> (permalink) |
| References | <48054.10.0.16.53.1322705364.squirrel@webmail.secure.aluminati.net> |
On 2011-12-01 16:51, Richard Smith wrote:
>
> C++11 permits an abstract class to be marked final. Such a class is nearly
> useless, and very likely to indicate user error. The clang developers would
> very much like to treat such classes as ill-formed; see:
>
> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-November/018865.html
<nod> I recently posted a similar problem description to the LWG, the
situation is even worse:
a) There is no requirement for a virtual class, just define
struct F1 final {};
b) The problem extends to other situations as well, where the
destructor is final, like in
struct F2 {
virtual ~F2() final;
};
The problem is expected to be observed not too rarely in the future,
once people start to use final in their daily code, because nowadays
libraries use EBCO quite extensively.
As a short term solution libraries will need an intrinsic that tests
whether given some type T the derived class definition
struct derived : T {};
would be well-formed.
Further, "user-code", especially third-party libraries, will
presumably need a standardized trait, e.g. std::is_derivable to
realize the same thing.
Hopefully there will be other long-term solutions, where final classes
or final destructors do not have such draw-backs. One idea that is
currently thought of is to invent a new attribute - name it
[[allow_empty]] - that can be even used for data members to allow
empty-data-member-optimization:
template<class T>
struct C {
[[allow_empty]] T t;
};
This last approach is very appealing because this would actually
promote better programming practices that do not abuse inheritance for
space optimization purposes.
HTH & Greetings from Bremen,
- Daniel Krügler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Find similar
Defect report: abstract final classes "Richard Smith"<richard@metafoo.co.uk> - 2011-12-01 07:51 -0800 Re: Defect report: abstract final classes Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-12-01 13:05 -0800
csiph-web