llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.99k stars 11.95k forks source link

std::is_default_constructible deletes default constructor #26254

Closed llvmbot closed 6 years ago

llvmbot commented 8 years ago
Bugzilla Link 25880
Resolution FIXED
Resolved on Apr 17, 2018 07:53
Version 3.7
OS Linux
Reporter LLVM Bugzilla Contributor
CC @programmerjake

Extended Description

Hello,

I've ran into an interesting issue, where, under certain circumstances, evaluating std::is_default_constructible::value has the unexpected side-effect of seemingly deleting T's implicit default constructor.

Here is a minimized test case

#include <type_traits>

struct Helper
{
    Helper() {}
    // one of the following two is required
    Helper(const Helper &) {}
    Helper(Helper &&) {}
};

struct Outer
{
    struct Inner
    {
        int x = 0;
    };

    Helper x;
    Inner y;

    Outer() {}

    // this has to be inside Outer (i.e. not global)
    static const bool delete_ctor_of_Inner =
        std::is_default_constructible<Inner>::value;
};

int main() {}

With both clang 3.6.2 and 3.7.0 the following error output is generated:

$ clang -std=c++14 test.cpp

test.cpp:21:5: error: constructor for 'Outer' must explicitly initialize the member 'y' which does not have a default constructor
    Outer() {}
    ^
test.cpp:19:11: note: member is declared here
    Inner y;
          ^
test.cpp:13:12: note: 'Outer::Inner' declared here
    struct Inner
           ^
1 error generated.

The libstdc++ is from GCC 4.9.2. With clang 3.5.0 it works.

Cheers, Jüri Valdmann

programmerjake commented 7 years ago

This appears to have been fixed in clang 4.0. https://godbolt.org/g/aDKYti

llvmbot commented 8 years ago

This bug is causing issues with upgrading Angelscript in SuperTuxKart: https://travis-ci.org/supertuxkart/stk-code/builds/140468833 https://github.com/supertuxkart/stk-code/pull/2525

Is there a workaround?