yohhoyの日記

技術的メモをしていきたい日記

新機能は属性 or 構文 or 関数?

プログラミング言語C++標準化プロセスにおける、新機能の対応方針についての考え方。2018年Jacksonville会合におけるEWG(Evolution Working Group)ガイダンス。

  • 構文上はオブジェクト(object)が対象のように見えるとしても、値(value)に関する属性を導入すべきでない。
  • コンパイラマジック関数で実現可能な機能について、コア言語機能(≒新しい構文)追加を行うべきでない。

C++2a(C++20)標準ライブラリに導入される、アドレス値アラインメント情報をコンパイラに与えるstd::assume_aligned関数の場合、当初提案*1では属性(attribute)とされていたが同ガイダンスに従い関数へと変更された。提案文書P1007R2より一部引用(下線部は強調)。

A previous paper [P0886R0] proposed to add this functionality to C++ through a new standard attribute, [[assume_aligned(N)]]. The guidance given by EWG in Jacksonville (2018) was that having this functionality in C++ is desirable, but not as an attribute. We should not introduce an attribute that appertains to values, even though syntactically it appears to appertain to objects. We also should not add a core language feature if this can be done in the library via a "magic" function.

P1007R2 std::assume_aligned, 4 Previous work and committee guidance