llvm / llvm/llvm-project

[Clang19][C++20] is_default_constructible assert fails conditionally on whether a member variable of that type is present in a class or not

Open
#159,764 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend concepts diverges-from:edg diverges-from:gcc diverges-from:msvc libstdc++
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

With clang 19.1.0 and c++20 the trait is_default_constructible results in different results for a pair containing a fundamental type and an aggregate with DMI (direct member initialisation) in a class if a member variable of such a pair type exists in the class or not.

Specifically the following fails to compile with the static_assert failing (https://godbolt.org/z/sGfcrnczx)
```cpp
#include
#include

class C {
public:
struct S {
int i = 0;
};
using test_type = std::pair;
test_type p;
C() {}
};

int main() {
C{};
static_assert(std::is_default_constructible::value, "failed");
return 0;
}
```

However the following code compiles just fine with the static_assert passing (https://godbolt.org/z/15f9b5eGd)

```cpp
#include
#include

class C {
public:
struct S {
int i = 0;
};
using test_type = std::pair;
// test_type p;
C() {}
};

int main() {
C{};
static_assert(std::is_default_constructible::value, "failed");
return 0;
}
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the two C++20 examples with Clang 19.1.0 using the linked Godbolt cases, comparing the results with and without the member variable. Trace the implementation of std::is_default_constructible and the relevant Clang diagnostic or type-trait handling; done means the trait gives the same expected result for both class definitions and the reproductions compile.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.