Topic: The expression without a type


Author: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 1999/12/24
Raw View
A friend of mine told me about a fascinating article:

http://research.microsoft.com/Users/luca/Papers/OnUnderstanding.ps

Among other things, that article convinced me that a good language
should have a type for each expression. If it doesn't, the type system
is not comprehensible and basically not too clever.

There are expressions that don't have a type in C++, only a couple I
think:

1. object.member_function and ptr->member_function

The result of the "." and "->" builtin operators for member functions
have a type, but one that cannot be named and expressed in C++. You
cannot create variables of that type etcetera.

2. obj.*pointer_to_member_function and
ptr->*pointer_to_member_function

Here things are worse. Storing the result of such expressions is often
needed for achieving generalized callbacks. What's very strange is
that you can overload operator->*, but you cannot have it mimic the
builtin operator->*, because the latter simply doesn't return an
expressible type! (See Scott Meyers' article in DDJ on overloading->*,
which discusses getting around this problem, without insisting on its
roots.)

Borland C++ has gotten around these issues by introducing a new
keyword (__closure).

One can argue that the name of a template falls in the same category,
but I wouldn't be so drastic. The result of operator->* comes from two
first-class objects, and doesn't have any rights as a type, which
seems to me very strange and awkward. Template names are much more
esoteric entities.

Before reading the article, I was aware of this problem, but I looked
at it as one of the many little problems that C++ has. Now it looks as
much more fundamental to me.

Three questions:

1. Is there a proposal to remediate this in the next revision of the
Standard?

2. Are there in C++ other expressions that yield no type?

3. Do other people think the above is important?


Best regards and Merry Christmas to all!

Andrei




[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]