नीचे दिया गया कोड ArchLinux पर clang 3.8.1-1
पर सही ढंग से संकलित करता है।फ़ंक्शन टेम्पलेट शीर्ष-स्तरीय कॉन्स के साथ घोषित पैरामीटर को संशोधित करता है: क्लैंग बग?
क्या यह clang
बग है?
gcc
इस पर सही चेतावनी/त्रुटि जारी करें।
template <class T>
struct BugReproducer{
using size_type = typename T::size_type;
int bug1(size_type count);
int bug2(size_type count) const;
static int bug3(size_type count);
};
template <class T>
int BugReproducer<T>::bug1(size_type const count){
// this is a bug. must be not allowed
count = 5;
// return is to use the result...
return count;
}
template <class T>
int BugReproducer<T>::bug2(size_type const count) const{
// same for const method
count = 5;
return count;
}
template <class T>
int BugReproducer<T>::bug3(size_type const count){
// same for static method
count = 5;
return count;
}
struct DummyVector{
using size_type = int;
};
int main(){
using BugRepr = BugReproducer<DummyVector>;
BugRepr reproducer;
auto a = reproducer.bug1(1);
auto b = reproducer.bug2(1);
auto c = BugRepr::bug3(1);
// return is to use the result...
return a + b + c;
}
यहाँ मैं कैसे संकलन:
[[email protected] HM3]$ clang x.cc -std=c++11 -lstdc++ -Wall -Wpedantic -Wconversion
clang
और c++14
- एक ही परिणाम।
[[email protected] HM3]$ clang x.cc -std=c++14 -lstdc++ -Wall -Wpedantic -Wconversion
यहाँ जीसीसी उत्पादन होता है:
[[email protected] HM3]$ gcc x.cc -std=c++11 -lstdc++ -Wall -Wpedantic -Wconversion
x.cc: In instantiation of ‘int BugReproducer<T>::bug1(BugReproducer<T>::size_type) [with T = DummyVector; BugReproducer<T>::size_type = int]’:
x.cc:46:28: required from here
x.cc:13:8: error: assignment of read-only parameter ‘count’
count = 5;
~~~~~~^~~
x.cc: In instantiation of ‘int BugReproducer<T>::bug2(BugReproducer<T>::size_type) const [with T = DummyVector; BugReproducer<T>::size_type = int]’:
x.cc:47:28: required from here
x.cc:22:8: error: assignment of read-only parameter ‘count’
count = 5;
~~~~~~^~~
x.cc: In instantiation of ‘static int BugReproducer<T>::bug3(BugReproducer<T>::size_type) [with T = DummyVector; BugReproducer<T>::size_type = int]’:
x.cc:48:20: required from here
x.cc:29:8: error: assignment of read-only parameter ‘count’
count = 5;
~~~~~~^~~
"क्लैंग बग रिपोर्ट" के लिए Google खोज करें। उपरोक्त समझ में नहीं आता है। ऑफ़-साइट संसाधनों के लिए दिशा-निर्देशों का अनुरोध यहां स्पष्ट रूप से ऑफ-विषय है। –
मैं संपादित कर दूंगा और अनुरोध को हटा दूंगा। लेकिन क्या यह एक बग है? – Nick
मैं नहीं देख सकता कि यह एक बग क्यों नहीं है - लेकिन एक रिपोर्ट क्यों न दर्ज करें, और देखें कि क्या झगड़ा ट्रायज़ कहता है? –