2014-12-09

2014-11-post-Urbanaのレビュー: N4301-N4309

[PDF] N4301: Working Draft, Technical Specification for C++ Extensions for Transactional Memory

トランザクショナルメモリーのTSドラフト

[PDf] N4302: Technical Specification for C++ Extensions for Technical Specification for C++ Extensions for Transactional Memory

N4301とほぼ同一。

N4303: Pointer safety and placement new

以下のコードは、C++14で挙動が定義された。

#include <new>
#include <cassert>

struct A { char buf[1]; };
struct B { char buf[1]; };

int main(void) {
    A a{ { 0 } };
    B *bp = static_cast<B *>(static_cast<void *>(&a));
    new (bp) B{ { 1 } };
    assert(bp->buf[0] == 1);
}

C++14では、static_castはaの先頭アドレスを指すことが明記されたので、上のコードは動作する。

ただし、これによって、コンパイラーのポインターの値によるエイリアシングの判定に誤りが生じる。そこで、この論文では、launderという関数を追加している。この関数にポインターの値を通すことによって、コンパイラーのアドレス値の解析を阻止するのだとか。

template <typename T> constexpr T* launder(T* p) noexcept;
Required behavior: An invocation of this function may be used in core constant expressions whenever the value of its argument may be used in a core constant expression.

Requires: p represents the address A of a byte in memory and an object Obj whose cv-unqualified type is remove_cv_t<T> is located at the address A.

Returns: A value of type T * which points to Obj.

そういう明示的なものが使われるとは思えない。

N4304: C++ Standard Core Language Active Issues
N4305: C++ Standard Core Language Defect Reports and Accepted Issues
N4306: C++ Standard Core Language Closed Issues

コア言語で現在議論中の問題、解決済みの問題、却下された問題の一覧。

[PDF] N4307: National Body Comment -- ISO/IEC PDTS 19568 -- Technical Specification: C++ Extensions for Library Fundamentals

Library Fundamentals TSに対するNBコメント集。日本からはmake_applyの追加というコメントが出ている。

[PDF] N4308: National Body Comment -- ISO/IEC PDTS 19570 -- Technical Specification: C++ Extensions for Parallelism

Parallelism TSに対するNBコメント集。

Return type deduction for explicitly-defaulted and deleted special member functions

特別なメンバー関数をdefault化、delete定義するときに、戻り値の型推定を許す提案。

以下のコードが、

struct X
{
    X & operator = ( X const & ) = default ;
    X & operator = ( X && ) = delete ;
}

以下のように書ける。

struct X
{
    auto operator = ( X const & ) = default ;
    auto operator = ( X && ) = delete ;
}

うーん・・・・、なんとも言いがたい。あって邪魔にはならない機能だが。

ドワンゴ広告

この記事はドワンゴ勤務中に書かれた。

ドワンゴは本物のC++プログラマーを募集しています。

採用情報|株式会社ドワンゴ

CC BY-ND 4.0: Creative Commons — Attribution-NoDerivatives 4.0 International — CC BY-ND 4.0

3 comments:

Anonymous said...

struct BとAが同じメモリレイアウトになることって保証されてましたっけ?
Bのbufの前に変なパディングが入ってsizeof(A)!=sizeof(B)になる可能性ありませんか?

江添亮 said...

ちょっと省略しすぎた。
論文ではキャストした後にplacement newをしてB型のオブジェクトを構築している

opbest said...


I’ve recently started a site, the information you offer on this site has helped me greatly. Thanks for all of your time & work.

Also visit my webpage - 부산오피

(freaky)