2016-12-22 4 views
9

は、次のコードを考えてみん:削除されたコンストラクタは - MSVCはエラーを報告し、クランはない

class SILPassPipelinePlan final { 
public: 
    SILPassPipelinePlan() = default; 
    ~SILPassPipelinePlan() = default; 
    SILPassPipelinePlan(const SILPassPipelinePlan &) = default; 
    SILPassPipelinePlan(SILPassPipelinePlan &&) = delete; 

    SILPassPipelinePlan x() { 
    SILPassPipelinePlan P; 

    return P; 
    } 
}; 

int main() { 
    return 0; 
} 

MSVCは、次のエラーが報告されます

1>consoleapplication2.cpp(13): error C2280: 'SILPassPipelinePlan::SILPassPipelinePlan(SILPassPipelinePlan &&)': attempting to reference a deleted function

1>consoleapplication2.cpp(8): note: see declaration of 'SILPassPipelinePlan::SILPassPipelinePlan'

クランとGCCにはありません。

仕様の観点からは、どのコンパイラが正しいですか?これはMSVCバグかClangバグですか?

MSVCは最新のVisual Studio 2015 Update 3のもので、Clangはバージョン3.9.0です。

+0

どの '-std'フラグをClangとGCCに渡していますか?移動コンストラクタの削除は、C++ 11とC++ 14の間で重要な変更を受けました。 – Angew

+0

@Angew特定のフラグはありません。ここで試してみてください:http://rextester.com/WJMW74714 –

+1

rextesterリンクに基づいて、 '-std = C++ 14'を使っています。この情報を質問に追加する必要があります。 – Angew

答えて

7

C++ 11は、特定のシナリオ— yours includedで暗黙移動を導入:

In the following copy-initialization contexts, a move operation might be used instead of a copy operation:

  • If the expression in a return statement ([stmt.return]) is a (possibly parenthesized) id-expression that names an object with automatic storage duration declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, or

  • […]

overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If the first overload resolution fails, […]

クラン削除機能の選択を含むように "失敗" 取り違え、又は[over.match.funcs]/8を適用するのいずれか(のみ受け入れる実装、BTW)。あまりにもひどい。バグ31025を参照してください。

+0

ありがとうございます。 'return const_cast (P);'のようなものはエラーを修正しますが、これには副作用がありますか? –

+1

@HBellamy 1つは、コピーエリシジョンが適用されないようにします。単純に提供していないのではなく、あなたが削除した*特定の理由はありますか?あなたは自分自身を提供しないということは、あなたのケースでは暗に宣言されないことを意味します。 [\ [class.copy.ctor \] /(8.1)](http://eel.is/c++draft/class.copy.ctor#8.1)を参照してください。 – Columbo

4

WCCのすべてのバージョンのGCCはこのコードを拒否します。 Macでこれをテストし、Clang-masquerading-as-GCCを使用していますか?

これはP0135とは関係ありません。クランは単に解像度が失敗しない過負荷、このような状況で

overload resolution to select the constructor for the copy is first performed as if the object were designated by an rvalue. If the first overload resolution fails or was not performed, [...], overload resolution is performed again, considering the object as an lvalue.

と言っていた、現在[class.copy.elision]/3あるものに「失敗」の過度リベラル読みを取っています。それが成功し、移動コンストラクタが選択されます。移動コンストラクタは削除されます。それは問題の終わりでなければならない。

これはbug 31025として報告されています。

+0

@columboどんな応答ですか? –

+0

@HBellamy何を言ってください?私はそれに応じて私の答えを修正した。 – Columbo

関連する問題