• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Const structure pointer as template argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Const structure pointer as template argument
      • From: Paul Walmsley <email@hidden>
  • Prev by Date: Re: can I catch an EXC_BAD_ACCESS?
  • Next by Date: Re: can I catch an EXC_BAD_ACCESS?
  • Previous by thread: Xcode attaching to signaled applications
  • Next by thread: Re: Const structure pointer as template argument
  • Index(es):
    • Date
    • Thread