I am writing a cross-platform application in two compilers (Clang on Xcode v5.0.2 and Visual Studio 2012 Update 4), and I came across a script in which two compilers do not agree with the required syntax for using the template keyword in a nested declaration.
Here is the code (reduced to an easily reproducible test case):
template<typename T> struct Base { template<typename U> struct InnerBase {}; }; template<typename T, typename U> struct Derived : public Base<T> {
As already noted, the two compilers do not agree with the use of the keyword "template".
For Clang, when the template keyword contains no , the error is:
Use the keyword 'template' to treat 'InnerBase' as a dependent template name
For Visual Studio, when template keyword is enabled , mistake:
'Base :: InnerBase': using a template template requires an argument list template
I looked at various StackOverflow questions regarding the rules for using the template keyword (for example, Where and why do I need to put the template “keywords”, etc.). However, looking at this and other similar questions, I’m not sure if there is one compiler implements C ++ 11 correctly and the other doesn't.
(Note that the Clang error makes sense to me, while the VS error doesn't make much sense to me because it seems like I'm including a list of template arguments.)
Which compiler is right in this case? If the template keyword should be included or not, in the above code example (for C ++ 11 compliance)?
(Perhaps I did not set the correct compiler settings to use C ++ 11 in one or the other case - in this case, my question still stands: which version of the code above is correct with C ++ 11?)
c ++ c ++ 11 templates clang visual-studio-2012
Dan nissenbaum
source share