C++ Logo


Advanced search

[wg14/wg21 liaison] N2539 / P2331R0 Unsequenced functions

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Thu, 25 Mar 2021 10:44:09 +0100
These look like possibly useful attributes for C++ as well,
but the wording needs to be totally redone.

First of all, these attributes assert certain facts about a
function to the compiler, which possibly cannot be deduced by
the compiler.
This is most useful if the compiler cannot "see" the definition
of the function. However, this wording contains quite a bit
of text talking about "is implied", meaning that the
compiler analyzes a function definition and then implicitly
adds the attribute to the definition. But if the
compiler can "see" the function definition, there is little
need for an implied attribute in the first place, because the
compiler already has all the information it can possibly infer
about the function (and it might inline the call anyway).

I'd like to see some explanation in the prose why the "is implied"
parts of the proposal are worth having. If "is implied" goes
away, the wording should be rephrased in the form of
assertions that the user makes, and should give the user
liberty to assert any function, without further constraints
on what the function actually does.

Special-casing call_once in all of this seems to be very much a
quality-of-implementation concern. Every implementation should
choose whether it wants to teach its optimizer about the
special "call_once" properties. (After all, this is all about
optimizations, which are optional anyway.)

 - It would help me if the wording would show monospace font where the
standard does, for example in p2 (list of attribute names)
and p1 (same).

 - "shall only appear" -> "shall appear only"

 - Since the new function attributes want to apply to a function
as declared (and not to the function type), they should apply to
the declarator-id and not to the entire function declarator.

 - p2 the first two sentences can be merged
"... that belongs to a function declarator that declares a function."

 - "forms the definition" is novel phrasing, and I don't know what it means.

 - p4+5 seems to contain tutorial material that shouldn't be in normative text

 - noleak: Any function -> All functions

Why do we have to mention allocation functions explicitly? They certainly
don't carry the "noleak" attribute, so the first bullet covers them

 - noleak: p3 This appears to define the term "storage leak",
but it's not used going forward. "can be deduced by the translator"
seems vague at best: some compilers can deduce more than others;
the specification of the standard needs to draw the line by explicitly
saying what's going on.

 - p4 "with the exception of an allocated return value"
What does that mean, exactly? When is a return value "allocated"?
Also "shall be" sounds like a Constraint, not a Description.

 - p2 "shall have the stateless attribute"
That seems a bit over-the-top. This attribute is an assertion by the programmer
to the compiler, so requiring that any called function has the stateless
attribute seems to hinder gradual adoption in a larger codebase
(where e.g. some third-party library function is known to be stateless,
but not (yet) annotated as such).

 - p2 "are const qualified variables that may range over the whole admissible set"
This feels like "value" is missing somewhere, e.g. "whose values may range over..."
What's the "admissible set" of function arguments?
Using const-qualified variables as function arguments doesn't do anything,
because the function parameter values are copies of those arguments anyway.
Also, I don't think the fact that something is const-qualified is the point
here, but the fact that no writes happen (you can choose not to write to
a non-const variable, too).

 - p4 says "A function designator is an expression that has function type."
You say "A function designator identified by an identifier f"
What if I have an expression of function type that is more than a simple identifier?

 - p4 talks about "the" function designator, which is an expression.
However, all that is in view here is a function definition. Where does the
expression come from?

 - p2 What does "objects for which the definition is met during the call" mean?
When do you "meet" a definition?


Received on 2021-03-25 04:44:14