Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Const structure pointer as template argument



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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.