`<array>`: `std::array<T,0>` calls constructors and destructors of `T`
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Describe the bug
A std::array<T,0> is meant to be an array of zero elements, but it's actually an array of one element as long as T is default-constructible in this implementation. This is clearly non-compliant.
Command-line test case
C:\Temp>type repro.cpp
#include <array>
#include <iostream>
struct S { S() { std::cout << "test failure\n"; } };
int main() {
std::array<S,0> s;
}
C:\Temp>cl /EHsc /W4 /WX /std:c++latest .\repro.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.36.32522 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
/std:c++latest is provided as a preview of language features from the latest C++
working draft, and we're eager to hear about bugs and suggestions for improvements.
However, note that these features are provided as-is without support, and subject
to changes or removal as the working draft evolves. See
https://go.microsoft.com/fwlink/?linkid=2045807 for details.
repro.cpp
Microsoft (R) Incremental Linker Version 14.36.32522.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:repro.exe
repro.obj
C:\Temp>.\repro.exe
test failure
Expected behavior
The program should print nothing.
STL version
https://github.com/microsoft/STL/commit/7841cf88ff9af837fb980f2d2d4ac0f267e714c7
Additional context
This is relevant to P3737R0: std::array is a wrapper for an array!
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 at stl/inc/array around lines 761-763 and reproduce the issue with the command-line example using a non-default-constructible or observable type. The fix is done when std::array<T, 0> performs no T construction or destruction and regression coverage confirms the program prints nothing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100