c++ - Why are C++11 override and final not attributes? -
i somehow missed attributes introduced in c++11. found out, i'm wondering why override
, final
added identifiers special meaning , not standard attributes.
the purpose of override
generate compile time error , purpose of many of standard attributes. feels if fit in concept there reason i'm missing.
they were, once, before got changed in response comment us 44 on c++11's fcd:
even if attributes continue standardized on continued objections both of 2 vendors cited principal prior art, can live them exception of virtual override controls. result awful, shown in example in 7.6.5 (excerpted):
class d [[base_check]] : public b { void some_func [[override]] (); virtual void h [[hiding]] (char*); };
here have 6 keywords (not counting
void
,char
): 3 normal keywords, , 3[[decorated]]
keywords. there has been public ridicule of c++0x ugliness. poor language design, in face of backward compatibility concerns (e.g., existing code may use words identifiers) because concerns have been resolved in other ways in existing practice (see below). more importantly, abuse of attributes disguised keywords objected , explicitly promised not happen in order proposal passed. use of attributes virtual control keywords egregious abuse of attribute syntax, , @ least use of attributes must fixed replacing them non-attribute syntax. these virtual override controls language features, not annotations.it possible have nice names , no conflicts existing code using contextual keywords, such recognizing word having special meaning when appears in grammar position no user identifier can appear, demonstrated in c++/cli has 5 years of actual field experience large number of customers (and no name conflict or programmer confusion problems reported in field during 5 years has been available):
class d : public b { void some_func() override; // same meaning [[override]] - explicit override virtual void h (char*) new; // same meaning [[hiding]] - new function, not override }; int override = 42; // ok, override not reserved keyword
the above forms implementable, have been implemented, have years of practical field experience, , work. developers love them. whether answer follow existing practice or else, there needs more natural replacement
[[attributed]]
keywords virtual override control ugly novelty has no field experience , developers have ridiculed.
Comments
Post a Comment