C++ Logo


Advanced search

Re: [wg14/wg21 liaison] [isocpp-sg21] Telecon to review P2388R1 Minimum Contract Support: either Ignore or Check_and_abort

From: Andrzej Krzemienski <akrzemi1_at_[hidden]>
Date: Fri, 24 Sep 2021 08:55:02 +0200
Aaron Ballman wrote:

There's a third concern in the same vicinity related to the use of
> [[]]. We've spent a decade teaching programmers that the positional
> placement of [[]] matters as to how it is interpreted by the compiler.
> void func(int i) [[attr]]; // attribute appertains to the function type
> void func(int i) [[contract:]]; // no impression that this impacts the
> type, but not certain either
> So if contracts don't behave like type attributes (which the standard
> doesn't currently make use of), it negates a lot of the educational
> effort on how to properly use attributes. Even though the standard
> doesn't use type attributes, users can use them with vendor specific
> attributes. For example, function type attributes are known to impact
> things like type checking; e.g., https://godbolt.org/z/3YzGb897f

Aaron Ballman also wrote:

Speaking as not-your-liaison but as the person responsible for
> attribute implementations in a few C++ compilers, this particular
> concern is not my biggest concern with the syntax. I'm *way* more
> concerned about the fact that these look like attributes when they're
> not actually attributes. This attribute-like syntax, coupled with
> where you write contracts, makes it *look* like the user has written a
> type attribute when the semantics of the contracts behave more like a
> declaration attribute. This muddies the language too much for me to
> support. One of the big reasons we got the [[]] syntax for attributes
> in the first place was because of known problems with attribute
> appertainment "sliding" to whatever construct makes most sense based
> on the spelling of the attribute, and that's essentially all this
> syntax achieves.

I need some help understanding what is considered a proper usage of a "type
attribute" in the context of function declaration.
It is quite easy to see in variable declarations: if one declaration
declares multiple variables, the type attribute would affect all the
But in case of a function declaration, there is only one function being
declared at a time.

You gave an example with [[gnu::fastcall]], and here the situation is quite
clear: it affects function type to the degree that I cannot cast it to a
pointer that doesn't have [[gnu::fastcall]].
But is this a determining factor? An attribute shall appertain to function
type if it modifies the type of the function?


Received on 2021-09-24 01:55:19