Const structure pointer as template argument
Const structure pointer as template argument
- Subject: Const structure pointer as template argument
- From: Ladd Van Tol <email@hidden>
- Date: Thu, 29 Jun 2006 16:15:32 -0700
I'm working on some legacy C++ code, and ran into an interesting
problem with some templates. I am not a language lawyer, so I wanted
to see if anyone could offer an opinion on this.
Basically the template is instantiated using a pointer to a struct.
If the pointer is to a const struct, I get bizarre and unhelpful
errors when compiling under Xcode 2.3:
templatetest.cpp:18: error: missing ‘>’ to terminate the template
argument list
templatetest.cpp:18: error: template argument 1 is invalid
templatetest.cpp:18: error: expected initializer before ‘>’ token
Through luck, I discovered that when I use a non-const struct, things
compile fine.
My reduced example is below:
------
typedef struct testStruct
{
long a;
} testStruct;
template <const testStruct * bob> class Helper
{
};
// this compiles
testStruct nonConstTestStruct = {0};
Helper<&nonConstTestStruct> HelperNonConst;
// this doesn't
const testStruct constTestStruct = {0};
Helper<&constTestStruct> HelperConst;
-----
Presumably it is harder for the compiler to deal with the const
example, as const variables can be coalesced by the linker. Still, if
the non-const struct is a valid argument, I would expect the const
struct to also be a valid argument. If not, a better error message
from GCC would be useful.
I have also filed a bug (#4608585)
- Ladd
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden