GCC and Clang disagree on whether template<typename>;
is a valid statement in C++ at global scope.
I'd expect it not to be allowed in the C++ standard because templatization pertains to declaration statements, not to expression statements and in consequence also not to null statements (the statement ;
).
So, is this a bug in Clang?
When specifying a template template, the class keyword MUST be used as above -- it is not interchangeable with typename in this case (note: since C++17 both keywords are allowed in this case).
" typename " is a keyword in the C++ programming language used when writing templates. It is used for specifying that a dependent name in a template definition or declaration is a type.
C++ templates are checked at least twice. First, when a template is declared & defined, second when it is instantiated. After a template successfully instantiated it is in a type safe state.
An individual class defines how a group of objects can be constructed, while a class template defines how a group of classes can be generated. Note the distinction between the terms class template and template class: Class template.
It's clang's idiosyncratic behavior that has existed for long time: missing declarations generate only a warning. It's just same as this:
int;
g++ would show an error, while clang will only show a warning. This doesn't contradict the standard.
warning: declaration does not declare anything [-Wmissing-declarations]
-Werror=missing-declarations
sets things straight.
Not really. The standard explicitly disallows such a declaration in [temp]p2;
The declaration in a template-declaration (if any) shall
declare or define a function, a class, or a variable, or
define a member function, a member class, a member enumeration, or a static data member of a class template or of a class nested within a class template, or
define a member template of a class or class template, or
be a deduction-guide, or
be an alias-declaration.
An empty-declaration doesn't match any of those clauses. Now the standard says that an implementation is required to issue a diagnostic message for any violation of its rules, like this one. Note that it says diagnostic, it doesn't specify whether a warning or an error (or even a note) is issued. The compiler can provide extensions that make what you wrote valid, as it wouldn't change the meaning of a well-formed program.
So no, both are right. However, clang's behavior is due to an extension, not something that the standard specifies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With