I often see people mentioning this self-imposed restriction, but it always looks like it does more harm than good.
Suppose that we do want a behavioral difference, like in this case, but we don't want introduce new productions to the grammar, keywords, etc, just some ad hoc syntax.
On Thursday, November 26, 2015 at 11:37:09 AM UTC-5, Vadim Petrochenkov wrote:I often see people mentioning this self-imposed restriction, but it always looks like it does more harm than good.
The standards committee has made it clear by now that making it easy to add keywords is something they don't want to do. Indeed, a proposal for a special feature to make adding keywords easier was shot down because "the difficulty of adding keywords to C++ is a feature".
Using attributes to back-door this restriction is not going to happen.
Suppose that we do want a behavioral difference, like in this case, but we don't want introduce new productions to the grammar, keywords, etc, just some ad hoc syntax.
Why don't we want some actual syntax here? Why is an "ad hoc" solution better than a real one?
And more importantly, why should the syntax be on the use of the type rather than on the type itself? That is, why not just have types that, when used as member subobjects, take up no space?
On Thursday, November 26, 2015 at 4:52:41 PM UTC, Nicol Bolas wrote:On Thursday, November 26, 2015 at 11:37:09 AM UTC-5, Vadim Petrochenkov wrote:I often see people mentioning this self-imposed restriction, but it always looks like it does more harm than good.
The standards committee has made it clear by now that making it easy to add keywords is something they don't want to do. Indeed, a proposal for a special feature to make adding keywords easier was shot down because "the difficulty of adding keywords to C++ is a feature".
Using attributes to back-door this restriction is not going to happen.
Suppose that we do want a behavioral difference, like in this case, but we don't want introduce new productions to the grammar, keywords, etc, just some ad hoc syntax.
Why don't we want some actual syntax here? Why is an "ad hoc" solution better than a real one?
It seems a perfect use of attributes to me. The feature is niche enough not to really warrant its own syntax or keyword and has a very minor effect on the program.
The "no behaviour change" restriction get repeated many times, but it is hardly respected ([[noreturn]], [[carries_dependency]]); The rule that seems to be followed is that a program stripped of all (or some) attributes is still a valid program.
template <typename T>
class test {
size_t size;
T internal [[allow_zero_size]];
};
struct empty_t {};
static_assert(sizeof(size_t) == sizeof(test<empty_t>), "Is the attribute set?");
And more importantly, why should the syntax be on the use of the type rather than on the type itself? That is, why not just have types that, when used as member subobjects, take up no space?
Because often the type is a template parameter (a function object, an allocator) and the library can't assume it has been correctly marked but might still want to take advantage of the optimization. Of course it should also be possible to tag a type.
>Why don't we want some actual syntax here? Why is an "ad hoc" solution better than a real one?I explained why, to avoid new extending the language grammar and reuse existing attribute grammar instead.
Many languages do this to introduce niche features, not important enough to deserve a full blown piece of syntax in the core language,
many pre-ISO attributes provided by C++ compilers do this as well.
On Thursday, November 26, 2015 at 12:02:02 PM UTC-5, Vadim Petrochenkov wrote:>Why don't we want some actual syntax here? Why is an "ad hoc" solution better than a real one?I explained why, to avoid new extending the language grammar and reuse existing attribute grammar instead.
OK, fair enough. Here's a better question.
Can you give a reason that the standards committee has not already heard and rejected several times over? Can you give a reason that would satisfy Herb Sutter?Many languages do this to introduce niche features, not important enough to deserve a full blown piece of syntax in the core language,
Can you give me some examples these "many languages" that use attributes for syntactic constructs? I'm hardly an expert in numerous languages, so I'm not contesting your statement.
But the only one I know of that makes extensive use of attributes (or syntax like attributes) is C#. And those are primarily for tagging C# constructs with arbitrary data that can be fetched via reflection.
many pre-ISO attributes provided by C++ compilers do this as well.
Sure they do. Compilers had ways to set the alignment of types and various other things. But notice that, when it came time to standardize this functionality, they became keywords. When those proposals were initially made, they did indeed use attribute syntax. But various people on the committee made them actual keywords, because they wanted attributes to be reserved for things that compilers could ignore.
When it comes time to standardize features, actual features go into the language, not into attributes.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.