From a practical point of view, I understand that both typedef
and test
are somewhat "superfluous" and need to be removed if we want the following code to compile:
template< typename type_t >
typedef struct tagTest
{
int a;
} test;
However, I thought that the set of typedef declarations was a subset of the set of declarations. They just happened to have that specific decl-specifier. That was my rationalization for
typedef struct tagTest
{
int a;
} test;
introducing the identifier test
and declaring the structure tagTest
. If that interpretation is correct, then the following paragraph from the standard should allow template
typedef
's (although not with the meaning given by the keyword using
).
The declaration in a template-declaration shall — (1.1) declare or define a function, a class, or a variable, or — (1.2) 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 — (1.3) define a member template of a class or class template, or — (1.4) be an alias-declaration.
I cannot see error in my reasoning, yet the conclusion is illegal.
What are the relevant parts of the standard that solve the above conundrum?
UPDATE
Part of the above reasoning uses the fact that typedef
struct
declares a structure. The typedef
specifier, as far as I understand it, implies that any variables declared are really types. That is, the typedef
upgrades test
from a mere variable to a type that is equivalent to the declared tagTest
. That is why the following code compiles (albeit with a warning).
typedef struct tagTest
{
int a;
};
tagTest t;
One of the answers takes care of the superfluous test
. But, it is possible to use typedef without a declarator because "Init-declarator-list is optional when declaring a named class/struct/union or a named enumeration"