2016-12-22 5 views
9

पर विचार करता है:हटाए निर्माता - 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'

बजना और जीसीसी नहीं है:

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 निम्न त्रुटि की रिपोर्ट।

एक विनिर्देश बिंदु से, कौन सा संकलक सही है? क्या यह एक एमएसवीसी बग है, या क्लैंग बग है?

एमएसवीसी नवीनतम विजुअल स्टूडियो 2015 अपडेट 3 से है, क्लैंग संस्करण 3.9.0 है।

+0

जो क्लैंग और जीसीसी से आप '-std' ध्वज गुजर रहे हैं? कन्स्ट्रक्टर हटाने को ले जाएं C++ 11 और C++ 14 के बीच महत्वपूर्ण परिवर्तन हुए हैं। – Angew

+0

@Angew कोई विशिष्ट झंडे। इसे यहां आज़माएं: http://rextester.com/WJMW74714 –

+1

उस रेक्स्टेस्टर लिंक के आधार पर, आप '-std = C++ 14' का उपयोग कर रहे हैं। आपको इस जानकारी को प्रश्न में जोड़ना चाहिए। – Angew

उत्तर

7

सी ++ 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, […]

बजना (। केवल स्वीकार करने कार्यान्वयन, Btw) या तो misinterprets "विफल रहता है" हटाए गए कार्यों का चयन शामिल करने के लिए, या [over.match.funcs]/8 लागू होता है बहुत लापरवाही बग 31025 देखें।

+0

धन्यवाद। कुछ 'वापसी const_cast (P);' त्रुटि को हल करता है - लेकिन क्या इसका दुष्प्रभाव है? –

+1

@HBellamy एक के लिए, यह कॉपी elision लागू होने से रोकता है। क्या कोई विशिष्ट कारण है कि आप * इसे प्रदान नहीं करने के बजाय * चालक ctor हटाएं? आप महसूस करते हैं कि स्वयं को उपलब्ध कराने का मतलब यह नहीं है कि आपके मामले में, किसी को भी निहित घोषित नहीं किया जाएगा? [\ [Class.copy.ctor \]/(8.1)] देखें (http://eel.is/c++draft/class.copy.ctor#8.1)। – Columbo

4

वंडबॉक्स पर जीसीसी के सभी संस्करण इस कोड को अस्वीकार करते हैं। क्या आप किसी मैक पर इसका परीक्षण कर रहे हैं और इसके क्लैंग-मास्कराइडिंग-ए-जीसीसी का उपयोग कर रहे हैं?

इसका P0135 से कोई लेना देना नहीं है। बजना बस के जरूरत से ज्यादा उदार पढ़ने ले जा रहा है "विफल रहता है" क्या वर्तमान में [class.copy.elision]/3 जो कहते है में, कि इस स्थिति

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.

संकल्प ओवरलोड कि विफल नहीं हुआ है; यह चालक को सफल बनाता है और चुनता है, जो हटाया जाता है। यह मामला का अंत होना चाहिए।

यह bug 31025 के रूप में रिपोर्ट किया गया है।

+0

@columbo कोई प्रतिक्रिया? –

+0

@HBellamy क्या कहो? मैंने तदनुसार मेरा जवाब संशोधित किया। – Columbo

संबंधित मुद्दे