Topic: non-type template arguments question
Author: "Paul Mensonides" <pmenso57@home.com>
Date: Tue, 7 Aug 2001 00:01:53 GMT Raw View
In the annotations to the C++ grammar in Stroustrup's "The C++ Programming
Language" pg. 806 it says:
[begin quote--
The list of specifiers that starts a declaration cannot be empty (there is not
"implicit int") and consists of the longest possible sequence of specifiers.
For example:
typedef int I;
void f(unsigned I) { /* ... */ }
Here, f() takes an unnamed unsigned int.
--end quote]
If that is true, is that true for template non-type argument declarations as
well?
i.e.
typedef int I;
template<unsigned I T> class X;
And is the reverse of the Stroustrup's example legal as well?
typedef unsigned U;
void f(U int) { /* ... */ }
If not, why not?
7.1.5 of the standard says:
[begin quote--
As a general rule, at most one type-specifier is allowed in the complete
decl-specifier-seq of a declaration.
The only exceptions to this rule are the following:
-- const or volatile can be combined with any other type-specifier. However,
redundant cv-qualifiers are prohibited except when introduced through the use of
typedefs (7.1.3) or template type arguments (14.3), in which case the redundant
cv-qualifiers are ignored.
-- signed or unsigned can be combined with char, long, short, or int.
-- short or long can be combined with int.
-- long can be combined with double.
--end quote]
According to this, I don't see why Stroustrup's example is legal in the first
place, since the keywords "signed," "unsigned," etc. are all in fixed-width font
(i.e. exact words).
The grammar reduces to the same productions for function parameters and for
non-type template arguments (I copied the relevant parts below.).
Does the standard explicitly disallow this for template non-type arguments? If
so, what section?
Paul Mensonides
NOTE: [...] indicates optional
( template stuff )
template-declaration:
[export] template < template-parameter-list > declaration
template-parameter-list:
template-parameter
template-parameter-list , template-parameter
template-parameter:
type-parameter
parameter-declaration <---------- // ----------
( function stuff )
function-definition:
[decl-specifier-seq] declarator [ctor-initializer] function-body
[decl-specifier-seq] declarator function-try-block
declarator:
direct-declarator
ptr-operator declarator
direct-declarator:
declarator-id
direct-declarator ( parameter-declaration-clause ) [cv-qualifier-seq]
[exception-specification]
direct-declarator [ [constant-expression] ]
( declarator )
parameter-declaration-clause:
[parameter-declaration-list] [...]
parameter-declaration-list , ...
parameter-declaration-list:
parameter-declaration <---------- // ----------
parameter-declaration-list , parameter-declaration
( common stuff )
parameter-declaration:
decl-specifier-seq declarator
decl-specifier-seq declarator = assignment-expression
decl-specifier-seq [abstract-declarator]
decl-specifier-seq [abstract-declarator] = assignment-expression
decl-specifier-seq:
[decl-specifier-seq] decl-specifier
decl-specifier:
storage-class-specifier
type-specifier
function-specifier
friend
typedef
type-specifier:
simple-type-specifier
class-specifier
enum-specifier
elaborated-type-specifier
cv-qualifier
simple-type-specifier
[::] [nested-name-specifier] type-name
[::] [nested-name-specifier] template template-id
char
wchar_t
bool
short
int
long
signed
unsigned
float
double
void
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]