4

This simple code:

#include <print>

int main()
{
    volatile int i = 5;
    std::println("{}", i);
}

Doesn't compile with any major implementation of the std library. Any particular reason why it doesn't have a formatter? Or is it just an omission?

Sample error:

error: static assertion failed due to requirement 'is_default_constructible_v<std::formatter<volatile int, char>>': std::formatter must be specialized for the type of each format arg

8
  • 1
    A side note: gcc up to and including14.2 accepted it, and stopped since 14.3 - see demo. Commented Nov 17 at 10:41
  • 1
    Close vote: You already asked the same question and got answers: stackoverflow.com/questions/79822128/… Commented Nov 17 at 10:45
  • 7
    @LéaGris it is not similar it is identical. That "advice" was created by mistake and should be deleted. I just can't do it. Commented Nov 17 at 10:45
  • So, to clarify, error disappears if you remove volatile? So the question is, why does that make a difference, is it required by the standard or just left unspecified, and perhaps also what other modifiers might cause it to not compile? Commented Nov 17 at 11:36
  • 2
    Workardound. Commented Nov 17 at 12:24

1 Answer 1

7

The current consensus in the Committee is to mostly ignore support for volatile in the library, see: P1831R1 Deprecating volatile: library.

Excerpt from parent paper P1152R0 Deprecating volatile:

We propose to deprecate, and eventually remove, volatile partial template specializations, overloads, or qualified member functions for all but the atomic and numeric_limits parts of the Library.

In other words, apart from the intentionally volatile nature of atomic components, the standard library is happy not to care about volatile.

Sign up to request clarification or add additional context in comments.

4 Comments

How do you search for these papers?
Much appreciated
Thanks for the answer, please, add to it that the papers mentioned were actually adopted for C++20.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.