c++/7166: Non-type template instantiation fails for pointer types
ofv@wanadoo.es
ofv@wanadoo.es
Sat Jun 29 14:32:00 GMT 2002
>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:
More information about the Gcc-bugs
mailing list