[cfe-dev] std::is_trivial_default_constructible<T>, what's required?!

Gabriel Charette via cfe-dev cfe-dev at lists.llvm.org
Thu Jan 25 07:35:44 PST 2018


On Thu, Jan 25, 2018 at 4:32 PM James Dennett <james.dennett at gmail.com>
wrote:

> On Thu, Jan 25, 2018 at 4:11 AM, Gabriel Charette via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> Hello Clang/C++ experts!
>>
>> I'm confused on what it takes to be std::is_trivial_default_constructible?
>>
>
> To be trivially default constructible means to be default constructible
> *without doing anything*.
>

Right... What I want is way to tell if the compiler will evaluate this at
compile-time (e.g. to guarantee no static initializer for globals of
trivial types with only zero-initialized POD members).


>
>
>>
>> This doesn't even compile (leaving x_ uninitialized compiles but I don't
>> see why it's not trivial to initialize a POD member inline):
>>
>> class Test {
>>  public:
>>   int x_ = 0;
>> };
>>
>> static_assert(std::is_trivially_default_constructible<Test>::value, "");
>>
>> -> error: static_assert failed due to requirement
>> 'std::is_trivially_default_constructible<Test>::value' ""
>>
>> I also tried making a constexpr Test() = default; constructor but I can't
>> get anything with POD members initialized inline to pass the
>> std::is_trivially_default_constructible test...?!
>>
>>
> If you need to initialize something, that's not trivial.
>
> -- James
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180125/cb312ed5/attachment.html>


More information about the cfe-dev mailing list