format (and friends) should reject volatile arguments#2579
format (and friends) should reject volatile arguments#2579StephanTLavavej merged 1 commit intomicrosoft:mainfrom
Conversation
... for now, at least. This corrects a defect in our implementation of [[format.args]/4](https://eel.is/c++draft/format.arg#4)'s requirement that: > ```c++ > typename Context::template formatter_type<remove_cvref_t<T>>() > .format(declval<T&>(), declval<Context&>()) > ``` be a valid expression. We were incorrectly stripping cv-qualifiers from `T`.
|
I'm open to suggestions for test coverage. I did verify that this program: #include <format>
#include <iostream>
int main() {
volatile int v = 42;
std::cout << std::format("{}\n", v);
}was accepted before and rejected after the change, but it's hard to do "correctly fails to compile" tests internally. |
|
Should your PR also close the issue #2427 ? Also the issue says that works. Should it be rejected too? |
miscco
left a comment
There was a problem hiding this comment.
I guess we have to wait for libc++ for compile.fail tests
|
Looks good to me. After reading through the surrounding code, I saw that: Lines 172 to 175 in 7b2c54b still implements the remove_cvref_t<T> mentioned in https://eel.is/c++draft/format.arg#4 .
|
|
See also #2246 |
I believe that behavior is consistent with the wording in the working draft; we should accept |
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
|
Thanks for handling this highly volatile issue! 🧪 🥼 😹 |
... for now, at least. This corrects a defect in our implementation of [format.args]/4's requirement that:
be a valid expression. We were incorrectly stripping cv-qualifiers from
T.