Here is my code:
class agg_t1{
int x; // private non-static data menber
};
class agg_t2{
agg_t2(){} // user-provided constructor
};
constexpr void ce1(agg_t1 arg){}; // OK
constexpr void ce2(agg_t2 arg){}; // ERROR: parameter type 'agg_t2' is not a literal type
According to dcl.constexpr:
The definition of a constexpr function shall satisfy the following requirements: ...
- each of its parameter types shall be a literal type; ...
A type is a literal type if it is: ...
- it is either a closure type, an aggregate type, or ...
I understand the reason why agg_t2
is not a literal type is that, it violates the rule dcl.init.aggr#1.1:
An aggregate is an array or a class with ...
- no user-declared or inherited constructors ...
and I think agg_t1
may not be a literal type because it violates the rule dcl.init.aggr#1.1 too:
An aggregate is an array or a class with ...
- no private or protected direct non-static data members ...
However... the compiler result tells me I was wrong about the assumption for agg_t1
.
My question is:
If agg_t1
's private data member x
makes it non-aggregate type ,then why the agg_t1
type is permitted in constexpr
function definition of ce1
?