Topic: String literals as template arguments


Author: daniel@lia.com (Daniel R. Edelson)
Date: Tue, 14 Sep 1993 18:18:22 GMT
Raw View
In article <1993Sep13.175440.849@borland.com>, pete@borland.com (Pete Becker) writes:

|> >>Ronald F. Guilmette <rfg@netcom.com> wrote:

|> >> What about these two? Is there a simple rule that's reasonably
|> >>intuitive to C programmers moving to C++?

|> >> template <const char *name> class Foo;
|> >>
|> >> Foo<"arg"> f1;
|> >>
|> >> const char * const cp = "arg";
                     ^^^^^ (added later)
|> >> Foo<cp> f2;


I joined this thread late. It may be everyone already realizes
the above code is *all* illegal, and you're simply trying to
determine what the new rules *should* be. However, if
anyone doubts that all this is technically illegal
according to the latest working paper, consider:

According to 14.2 a non-type template argument must be:
 1) a constant expression,
 2) the address of an object or function with external linkage, or
 3) a static class member.
Items 2 and 3 clearly don't apply. (Note, string literals don't have
external linkage and "cp" in the above is not the address of an object,
it's an object.)


As far as constant expressions, 5.19 says:
 ``... except in sizeof expressions, pointers cannot be used.''

--
Daniel R. Edelson     | ``Shh. This is my favorite deodorant commercial.''
daniel@lia.com        |                                            -calvin
IA Corp., Alameda, CA |



--
Daniel R. Edelson     | ``Shh. This is my favorite deodorant commercial.''
daniel@lia.com        |                                      - Calvin
IA Corp, Alameda, CA  |