STL icon indicating copy to clipboard operation
STL copied to clipboard

`<regex>`: Constants in `std​::​regex_constants` are not `constexpr` variables

Open frederick-vs-ja opened this issue 2 years ago • 4 comments

Describe the bug

The Standard specified that constants in std::regex_constants to be constexpr variables ([re.const]).

However, MSVC STL just implements them as enumerators of unscoped enumerations, which are not variables.

It seems that they have never been specified be to non-object. In TR1 (WG21-N1836) they were static const variables.

Command-line test case

Godbolt link

Additional context

libc++ is similarly buggy (llvm/llvm-project#69420).

Also tracked by VSO-498998 / AB#498998 .

frederick-vs-ja avatar Oct 18 '23 04:10 frederick-vs-ja

Did you have an actual problem with a program you wrote, or is this just a paper bug report? I think it's better that these constants are prvalues - they don't waste space in object files. We should consider submitting an LWG issue to allow our implementation. (I suspect C++11 used constexpr variables out of an abundance of enthusiasm for the new feature, and not for any technical reason.)

CaseyCarter avatar Oct 18 '23 06:10 CaseyCarter

I think it's better that these constants are prvalues - they don't waste space in object files.

Oh, WG21-P0439R0 may be related - it changed previous enumerators to constexpr variables. But in C++20 there's using enum, so it's possible to keep the constants in std being prvalues while making std::memory_order scoped.

frederick-vs-ja avatar Oct 18 '23 06:10 frederick-vs-ja

We talked about this at the weekly maintainer meeting and we're basically in agreement that this is legitimately a conformance issue, albeit one of extremely limited importance, and we would accept a PR to resolve this.

StephanTLavavej avatar Oct 18 '23 21:10 StephanTLavavej

LWG-3998 is opened for this. Perhaps we can add "decision needed" back?

frederick-vs-ja avatar Oct 21 '23 10:10 frederick-vs-ja