-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Tracking Issue for constexpr Containers: P0784, P0980, P1004 #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the amazing writeup! |
Fairy magic might be appropriate :). What the compiler actually does is elide calls to those functions (along with |
I mean why don't we use |
Great bookkeeping for feature implementation quality, Miya! |
This was addressed in the STL discord channel as well, but for the sake of completeness I will echo the reasoning here. Allowing Unless |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Someone with access to the Microsoft-internal bug database needs to make a pass over the OP and ensure everything is up-to-date. The "Active EDG bugs" all seem to be closed and resolved, for example. If we can remove any and all workarounds, we can close this issue. |
Last updated 1/11/2022
📄 Relevant Papers
constexpr
Containersconstexpr std::string
constexpr std::vector
🚧 Status
The various papers involved in this broader feature are in various stages of completion:
🎈 Fixed Clang Bugs
Resolved in Clang 12
is_constant_evaluated()
can incorrectly evaluate to true in the destructor of a non-constexpr variableResolved in Clang 13
-Wdangling-gsl
incorrect warns on return by value ofstd::string::iterator() -= n
- workaround applied ⚠🐞 Active C1XX Bugs (MSVC Front-End)
constexpr
evaluation - not blocking for MSVC, found workaroundnext = &(*next)->s.p;
-->U* temp = *next; next = &temp->s.p;
const
variables during constant evaluation - not blocking 🟢cl
permits copying into memory before object lifetimes have begun - not blocking 🟢constexpr
ICE: binding a reference to a temporary emitsAssertion failed: Nerrors > 0
- not blocking for MSVC, have workaround_INLINE_VAR constexpr _Fake_allocator _Fake_alloc{};
constexpr
dynamic allocation doesn't properly understandstd::construct_at()
"vector<Base*>
, no workarounds in STL product/test code.std::{ranges::}construct_at
when passed a string literal as argument"<memory>
:std::construct_at(s, " ")
did not evaluate to a constant #2467🎉 Fixed C1XX Bugs (MSVC Front-End)
constexpr
destructors disallowed in literal types in parameters, return typesconstexpr
does not evaluate explicit dtor callconstexpr
does not respect lvalue reference to class temporariesconstexpr
tostd::string
in Back-Endusingconstexpr std::string
std::construct_at
requires a copy constructorcl
errors onconstexpr
array ofstd::string
cl constexpr
temporary passing issueprotected
std::optional
with RapidJSON which contains this code pattern).cl
does not make special member functions implicitlyconstexpr
- not blocking for MSVC, have workaround from @cdacamar🦗 Active EDG Bugs
_wassert
notconstexpr
- large portions of tests disabled for EDG 😢constexpr
function🥳 Fixed EDG Bugs
/BE
- related tostd::destroy
cl
Incorrectly rejects class with destructor for constant evaluation with/BE
constexpr std::string
indo_constexpr_std_construct_at
__builtin_memcmp
emits bogus errors with move-constructed strings and constexpr dynamic allocations📑 Compiler Approaches to
constexpr
Dynamic Allocation(from @cdacamar in #1532) Note that [expr.const]/5 states that an expression E is a core constant expression unless the evaluation of E would [...] would evaluate one of the following:
std::allocator::allocate
([allocator.members]), unless the allocated storage is deallocated within the evaluation of E;std::allocator::deallocate
([allocator.members]), unless it deallocates a region of storage allocated within the evaluation of E;So, the expression
::operator new
is not anew
expression, it is a function call to a globaloperator new()
which is not aconstexpr
function.::operator new
in aconstexpr
function if it is reached transitively from an evaluation ofstd::allocator::allocate
.std::allocator::allocate
,std::allocator::deallocate
, but does not allow::operator new
.::operator new
, but we choose to have the EDG logical paths mirror those for MSVC so they work in tandem.Development notes, preserved for history
👣 Next Steps (as of Jan 2021)
mutable
, but Clang currently does not allow this due to this bug.vector
variables can exist, we need to enable situations where a variable is constant initialized (sostd::is_constant_evaluated()
evaluates totrue
in the constructor), but not necessarily constant evaluated (sostd::is_constant_evaluated()
evaluates tofalse
in subsequent calls to other member functions). You can see the discussion here.std::is_constant_evaluated()
istrue
in these containers in general. Hopefully, a fix for Bug 48606: Clang rejects creation of struct with mutable member during constant evaluation can be forthcoming soon, in which case we will be able to move forward with a Clang-facing implementation.mutable
in this context, or (2) investigate whether requested an additional built-in to detect whether we are in a "constant initialization" context vs. "constant evaluation" context could also help us mitigate the debug iterators issue.string
variable will end up using a dynamic initializer as constant initializers will be off-limits. This is because we don't have non-transient allocations and all constant initializers forstring
now do constant-time allocation (since SSO is turned off ifis_constant_evaluated()
). So, the motivating argument for keeping the debug iterator proxy machinery active during constant evaluation does not apply tostring
, but the same iterator logic is used by many of the containers. Only disabling the proxy iterator things forstring
would require duplication of a lot of code. Given that there are plans to update our debug iterator machinery in vNext anyway, the effort required to disable debug iterators during constant-time forstring
does not seem worthwhile.🖥️ Testing (as of Jan 2021)
#ifdef MSVC_INTERNAL_TESTING
) so as to discover and fix compiler issues more quickly.MSVC_INTERNAL_TESTING
.P1004R2_constexpr_vector
tests are passing internally with the updated compiler -- Enable constexpr vector internal tests #1690 enables the tests internally. When we consume the updated compiler with test fixes, we will be able to remove thedefined(MSVC_INTERNAL_TESTING)
entirely.P1004R2_constexpr_vector_bool
tests have all compiler bugs fixed internally, but there is a pre-existing issue in the debug iterator machinery that needs investigation before we can enable these tests.P0980R1_constexpr_string
tests have all compiler bugs fixed internally, and will already havedefined(MSVC_INTERNAL_TESTING)
throughout test code to enable these tests internally as soon as we merge.The text was updated successfully, but these errors were encountered: