public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/7166: Non-type template instantiation fails for pointer types
@ 2002-06-30 2:58 nathan
0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-06-30 2:58 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, ofv
Synopsis: Non-type template instantiation fails for pointer types
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Sun Jun 30 02:57:04 2002
State-Changed-Why:
not a bug. Like the error says, you are attempting to
instantiate a template on a non-externally visible object
(the thing pointer to *by* strPointer). The array case
works becuase of array->pointer decay - the thing pointed
to is the first array element, and that does have external
linkage. May be you mean to write
template <char const *&r> class Foo {};
which would be acceptable for the first case, as then you're
binding to the pointer variable.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7166
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++/7166: Non-type template instantiation fails for pointer types
@ 2002-06-29 13:36 ofv
0 siblings, 0 replies; 2+ messages in thread
From: ofv @ 2002-06-29 13:36 UTC (permalink / raw)
To: gcc-gnats
>Number: 7166
>Category: c++
>Synopsis: Non-type template instantiation fails for pointer types
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Sat Jun 29 11:56:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: ofv@wandoo.es
>Release: gcc 3.1
>Organization:
>Environment:
d:/Des/cppExp # gcc -v
Reading specs from t:/msys/1.0/mingw/bin/../lib/gcc-lib/mingw32/3.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.1
It fails too with gcc 3.1 (cygwin) and gcc 2.95.3-6 (MinGW)
>Description:
Instantiating a template with a non-type parameter of pointer type makes the compiler complain about the parameter not being an object with external linkage. So far I've only tried with char* and int*. It works for char[] and int[].
See test case below.
>How-To-Repeat:
Compiling this:
/// begin
template <char *p> class FooChar {};
char *strPointer = "Hi!";
char strArray[] = "Hi!";
template <int *p> class FooInt {};
int *intPointer = 0;
int intArray[] = { 1, 2 };
int main() {
FooChar<strPointer> fooCharPointer;
FooChar<strArray> fooCharArray;
FooInt<intPointer> fooIntPointer;
FooInt<intArray> fooIntArray;
}
/// end
produces
g++ -c gccbugTPointer.cpp
gccbugTPointer.cpp: In function `int main()':
gccbugTPointer.cpp:12: `strPointer' is not a valid template argument
gccbugTPointer.cpp:12: it must be the address of an object with external linkage
gccbugTPointer.cpp:12: ISO C++ forbids declaration of `fooPointer' with no type
gccbugTPointer.cpp:15: `intPointer' is not a valid template argument
gccbugTPointer.cpp:15: it must be the address of an object with external linkage
gccbugTPointer.cpp:15: ISO C++ forbids declaration of `fooIntPointer' with no type
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-06-30 9:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-30 2:58 c++/7166: Non-type template instantiation fails for pointer types nathan
-- strict thread matches above, loose matches on Subject: below --
2002-06-29 13:36 ofv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).