Topic: Literal class types and trivial default constructor


Author: Inconnu <shirarenai@yandex.ru>
Date: Thu, 27 May 2010 00:24:22 CST
Raw View
In the latest draft, one of the requirements for the class to be
literal is that it has "a trivial default constructor or at least one
constexpr constructor other than the copy constructor". But it seems
to me that the connection between the class's being literal and the
existence of a trivial default constructor is quite weak. For example,

struct A {int x; };
struct B : A {int y; };

class B is literal, according to the draft, but a value of that class
can in no way be initialized as a constant, because it has a base
class.

On the other hand:

struct C
{
  int a, b;
  constexpr C (x, y) : a (x), b (y) {}
};
struct D
{
 int x;
 C c;
};

Here class D doesn' have a default constructor at all (as well as
constexpr constructors), but it seems to be quite literal, because it
can be initialized as aggregate:

constexpr D d {1, {2, 3}};

I propose to change the above cited wording from the draft to:
"is an aggregate class or has at least one constexpr constructor other
than the copy constructor"

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]