Created on 2025-06-17.00:00:00 last changed 1 month ago
(From submission #716.)
The following note added to 9.13.1 [dcl.attr.grammar] by issue 2695 embodies the design intent that attributes can be ignored by implementations:
[Note 5: The attributes specified in 9.13 [dcl.attr] have optional semantics: given a well-formed program, removing all instances of any one of those attributes results in a program whose set of possible executions (4.1.2 [intro.abstract]) for a given input is a subset of those of the original program for the same input, absent implementation-defined guarantees with respect to that attribute. -- end note]
However, the note is incorrect for attributes that contain a potentially-evaluated expression such as [[assume]] (9.13.3 [dcl.attr.assume]). For example,
template<int N> struct reader { friend auto flag(reader); }; template<int N> struct setter { friend auto flag(reader<N>) {} }; template<int N = 0, auto DifferenceMaker = [] {}> consteval int next() { if constexpr (requires { flag(reader<N>{}); }) { return next<N + 1>(); } else { (void) setter<N>{}; return N; } } int main() { static_assert(next() == 0); [[assume(true || next())]]; static_assert(next() == 2); }
While this particular example using stateful friend injection is addressed by issue 2118, similar examples can be constructed using mainstream facilities introduced by P2996R13 (Reflection); see the compile-time ticket counter example therein.
There are also counterexamples for [[no_unique_address]].
Forwarded to EWG with paper issue 2407, by decision of the CWG chair.
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-06-17 00:00:00 | admin | create |