Topic: Definition of type-dependant and value-dependant expressions


Author: patrick@webmasters.com (patrick)
Date: Tue, 10 Jan 2006 01:03:51 GMT
Raw View
Hello

The definition of dependant expressions in 14.6.2, 14.6.2.2 and 14.6.2.3 =
is
very convoluted and unintuitive.

Let's first quote the general definition of dependant expressions :


"Inside a template, some constructs have semantics which may differ from =
one
instantiation to another. Such a construct depends on the template
parameters. In particular, types and expressions may depend on
the type and/or value of template parameters (as determined by the templa=
te
arguments) and this determines the context for name lookup for certain
names. Expressions may be type-dependent (on the type of a template
parameter) or value-dependent (on the value of a non-type template
parameter)."


Later, 14.6.2.3/2 states that "sizeof unary-expression" is value-dependan=
t
if "unary-expression" is type-dependant (even if "sizeof unary-expression=
"
is not type-dependant).

Let's examine an example :

template<typename T>
void f() {

=A0 sizeof T();
}


In this example, T() is clearly type-dependant. Thus, according to
14.6.2.3/2, sizeof T() is value-dependant. But this contradicts completel=
y
the general definition of value-dependant expressions as depending on the
value of a non-type template parameter (there is no non-type template
parameter in this example).

I think it would be clearer to define a type-dependant expression as an
expression whose type depends on a template parameter, and a
value-dependant expression as an expression whose value depends on a
template parameter.

The problem with the current wording is that it first defines a concept
clearly (in 14.6.2/1), and then obfuscates it in the following clauses, s=
o
as to make it completely incomprehensible.



Patrick

---
[ 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.jamesd.demon.co.uk/csc/faq.html                       ]