C++14ではヌルポインタ定数の定義における値0
の扱いが微妙に変更される。CWG defect #903の適用。
下記コードにおいて、C++11以前ではg<0>
のみwell-formedとなり、それ以外(g<1>
など)はill-formedとなる。C++14では非型テンプレートパラメータNへの指定値によらずill-formedとなる(一貫性向上)。
template <int N> void g() { int* p = N; // ?? } g<0>(); // C++11: OK / C++14: NG g<1>(); // C++11/14: NG
C++11以前
N3337(C++11) 4.10/p1より該当箇所を引用(下線部は強調)。*1
A null pointer constant is an integral constant expression (5.19) prvalue of integer type that evaluates to zero or a prvalue of type
std::nullptr_t
. (snip)
C++14
N3937(C++14 DIS) 4.10/p1より該当箇所を引用(下線部は強調)。
A null pointer constant is an integer literal (2.14.2) with value zero or a prvalue of type
std::nullptr_t
. (snip)
関連URL
- C++ Standard Core Language Defect Reports, #903 Value-dependent integral null pointer constants
- 本の虫: C++03とC++14の違い:標準型変換編
- ブログズミ: ポインター引数に FALSE を渡してしまった…その時 C++14 では…
- nullptrキーワード - yohhoyの日記
- ヌルポインタの内部表現 - yohhoyの日記