When we implemented restrict in the KAI C++ compiler (and later forwarded
the changes to EDG), I was faced with the decision of whether restrict
should affect overloading or not.
My decision was that it should not, because you are supposed to be able
to replace restrict with whitespace and still have a correct program.
This is essential for providing a migration path.
But there are also some other arguments against overloading based on
restrict. In particular, the const analogy does not hold up.
Consider:
void foo( float * restrict p, float * restrict q ) {
float * x = p;
float * y = q;
bar( p, q );
bar( x, y );
*p = *q;
*x = *y;
}
The program is legal. Note that restrict was implicitly cast away.
Even so, the compiler can infer tha *x and *y are disjoint if referenced,
just as it can for *p and *q.
However, if I change "restrict" to "const" (or "volatile") the example
become illegal C++, because "const" and "volatile" cannot be implicitly
cast away.
There's also another fault in the analogy. Consider the suggested example:
> template <class T> copy(T const * restrict, ...) { memmove(...); ...; }
>
> should be different from
>
> template <class T> copy(T const * /*aliased*/, ...) { ...; }
If you change the "restrict" to "volatile", the two prototypes are in fact
considered the same in C++, because top-level qualifiers are mostly ignored
for declaration matching.
Also note that rvalues such as:
p+1
lose their top-level qualifications, so bar(p+1,q+1) would use the unrestricted version.
I think that the fundamental flaw in the analogy is that "const" and "volatile"
deal with single lvalues, whereas "restrict" says something about a *pair*
of lvalues.
Arch D. Robison Kuck & Associates Inc.
robison@kai.com 1906 Fox Drive
217-356-2288 ext. 56 Champaign IL 61820
Lead Developer for KAI C++ http://www.kai.com/C_plus_plus/index.html
--------------------- Object Oriented Numerics List --------------------------
* To subscribe/unsubscribe: use the handy web form at
http://oonumerics.org/oon/
* If this doesn't work, please send a note to owner-oon-list@oonumerics.org
This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 03:20:12 EST