<concepts>: std::default_initializable accepts types that are not default_initializable
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Describe the bug
While implementing std::default_initializable in libc++ (https://reviews.llvm.org/D93461) I noticed some difference between libstdc++ and libc++ versus MSVC. I believe the MSVC implementation accepts types as std::default_initializable while they shouldn't be accepted. @CaseyCarter this is probably something you want to look at.
Command-line test case
The code is tested with Godbolt with MSVC v19.28 using the option /std:c++latest
https://godbolt.org/z/7dc5Kq
#include <concepts>
int main() {
struct S0 { explicit S0() = default; };
S0 x0;
S0 y0{};
static_assert( std::constructible_from<S0>);
static_assert( std::default_initializable<S0>);
struct S1 { S0 x; }; // Note: aggregate
S1 x1;
//S1 x3{}; // MSVC accepts this line, clang and gcc reject it.
static_assert( std::constructible_from<S1>);
// Only MSVC fails assert, probably due to accepting S1 x3{};
static_assert(!std::default_initializable<S1>);
const int y20{};
// const int y21; // All compilers reject this line.
static_assert( std::constructible_from<const int>);
// Only MSVC fails static_assert at line below
static_assert(!std::default_initializable<const int>);
const int y30[1]{};
//const int y31[1]; // All compilers reject this line.
static_assert( std::constructible_from<const int[1]>);
// Only MSVC fails static_assert at line below
static_assert(!std::default_initializable<const int[1]>);
// Zero-length array extension
static_assert(!std::constructible_from<const int[]>);
static_assert(!std::default_initializable<const int[]>);
}
Expected behavior
- I expect the line
S1 x3{};to be rejected by MSVC, this might be a compiler bug and not a library bug. - I expect all
static_assertsto pass.
STL version
Godbolt using MSVC v19.28
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the command-line test case on Godbolt using MSVC v19.28 and /std:c++latest, then compare its behavior with libstdc++ and libc++. Review std::default_initializable and the listed static_asserts to determine whether the discrepancy belongs to the STL or the compiler. Done means the ownership of the bug is established and the expected assertions behave consistently.
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
- 35/100