के साथ नहीं, जीसीसी 4.7.2 और क्लैंग 3.1 दोनों के साथ कुछ सी ++ 11 कोड संकलित करते समय, मैं क्लैंग के साथ एक समस्या में भाग गया जहां टेम्पलेट तर्क को कम करने के लिए प्रबंधन नहीं किया गया था जीसीसी सफल एक और अधिक सार रूप में, कोड इस तरह दिखता है:टेम्पलेट पैरामीटर के रूप में वैराडिक टेम्पलेट: कटौती जीसीसी के साथ काम करता है लेकिन क्लैंग
src/test.cc:
struct Element {
};
template <typename T>
struct FirstContainer {
};
template <typename T, typename U = Element>
struct SecondContainer {
};
template <template <typename> class Container>
void processOrdinary(Container<Element> /*elements*/) {
}
template <template <typename, typename> class Container>
void processOrdinary(Container<Element, Element> /*elements*/) {
}
template <template <typename, typename...> class Container>
void processVariadic(Container<Element> /*elements*/) {
}
int main() {
// This function instantiation works in both GCC and Clang.
processOrdinary(FirstContainer<Element>{});
// This function instantiation works in both GCC and Clang.
processOrdinary(SecondContainer<Element>{});
// This function instantiation works in both GCC and Clang.
processVariadic(FirstContainer<Element>{});
// This function instantiation works in both GCC and Clang.
processVariadic<SecondContainer>(SecondContainer<Element>{});
// This function instantiation works in GCC but not in Clang.
processVariadic(SecondContainer<Element>{});
return 0;
}
मानक के §14.8.2 में §14.3.3 में उदाहरण और विशिष्टताओं को पढ़ने से मुझे लगता है कि कटौती काम करनी चाहिए, लेकिन मैं निश्चित रूप से नहीं कह सकता। यह मुझे उत्पादन से प्राप्त आउटपुट है:
mkdir -p build-gcc/
g++ -std=c++0x -W -Wall -Wextra -Weffc++ -pedantic -c -o build-gcc/test.o src/test.cc
g++ -o build-gcc/test build-gcc/test.o
mkdir -p build-clang/
clang++ -std=c++11 -Weverything -Wno-c++98-compat -c -o build-clang/test.o src/test.cc
src/test.cc:34:3: error: no matching function for call to 'processVariadic'
processVariadic(SecondContainer<Element>{});
^~~~~~~~~~~~~~~
src/test.cc:21:6: note: candidate template ignored: failed template argument deduction
void processVariadic(Container<Element> /*elements*/) {
^
1 error generated.
make: *** [build-clang/test.o] Fel 1
परिणाम अलग क्यों हैं? क्या जीसीसी मैला, क्लैंग गूंगा है, क्या मेरे कोड में अनिर्दिष्ट व्यवहार या उनमें से सभी शामिल हैं?
मैं आपसे सहमत हूं। सी ++ 11 अंतिम मसौदे में जो कुछ भी मैंने देखा है, वह इंगित करेगा कि यह काम करना चाहिए। 14.3.3.3 विशेष रूप से प्रासंगिक है। –
आपके उदाहरण में 'typedef int Element; 'है, है ना? – Quuxplusone
नहीं, कोड की शुरुआत में मैं एलिमेंट नाम के साथ एक संरचना को परिभाषित करता हूं। – psyill