Assuming of course that the instantiation statement is ok.
As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
(and Borland) but since I was suspicious that it was OK there "more by luck
than brain", I checked the same on Linux\GNU were the instantiation failed.

This question is more for people who know well the C++ ISO standard, in the
chapter on template. My hunch is that the problem is with the language spec.

Thanks

Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by Simon

Simon
Wed May 12 19:53:20 CDT 2004

"David F" <David-White@earthlink.net> wrote in message
news:pezoc.18145$Hs1.10044@newsread2.news.pas.earthlink.net...
> Assuming of course that the instantiation statement is ok.
> As a matter of fact, that very instantiation passes successfuly on VC++
7.1
> (and Borland) but since I was suspicious that it was OK there "more by
luck
> than brain", I checked the same on Linux\GNU were the instantiation
failed.
>
> This question is more for people who know well the C++ ISO standard, in
the
> chapter on template. My hunch is that the problem is with the language
spec.
>
> Thanks

I'm not sure if I understand you right. It's not only possible, it's common:

template<class B> struct D
{
void D() { B::C(); }
};

This will fail to compile on the instantiation if, and only if, B has no
member C() that has either none or all default parameters.

So:

struct E: D<E> { int C(); }; // fine
struct F: D<F> {}; // oops

S.



Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by David

David
Wed May 12 20:50:48 CDT 2004

There was no intention to trick with the question.
Nor was it intended to relate to some too trivial cases as you brought up.
So please read it again.
I did write that it passes successfully two compilers and I don't think that
it would if there would be such a trivial mistake on the programmer's part
as you described.
Regretfully, for commercial reasons, I am not at liberty to publish the
code, not even the very few lines that demonstrate the problem.


"Simon Trew" <ten.enagro@werts> wrote in message
news:u4t8uSIOEHA.1348@TK2MSFTNGP12.phx.gbl...
> "David F" <David-White@earthlink.net> wrote in message
> news:pezoc.18145$Hs1.10044@newsread2.news.pas.earthlink.net...
> > Assuming of course that the instantiation statement is ok.
> > As a matter of fact, that very instantiation passes successfuly on VC++
> 7.1
> > (and Borland) but since I was suspicious that it was OK there "more by
> luck
> > than brain", I checked the same on Linux\GNU were the instantiation
> failed.
> >
> > This question is more for people who know well the C++ ISO standard, in
> the
> > chapter on template. My hunch is that the problem is with the language
> spec.
> >
> > Thanks
>
> I'm not sure if I understand you right. It's not only possible, it's
common:
>
> template<class B> struct D
> {
> void D() { B::C(); }
> };
>
> This will fail to compile on the instantiation if, and only if, B has no
> member C() that has either none or all default parameters.
>
> So:
>
> struct E: D<E> { int C(); }; // fine
> struct F: D<F> {}; // oops
>
> S.
>
>



Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by benben

benben
Thu May 13 01:21:28 CDT 2004

Hmmm...David, I do think it would be better if you bring up a couple of
examples of what you have asked. I don't REALLY get your story...

ben

> There was no intention to trick with the question.
> Nor was it intended to relate to some too trivial cases as you brought up.
> So please read it again.
> I did write that it passes successfully two compilers and I don't think
that
> it would if there would be such a trivial mistake on the programmer's part
> as you described.
> Regretfully, for commercial reasons, I am not at liberty to publish the
> code, not even the very few lines that demonstrate the problem.
>
>
> "Simon Trew" <ten.enagro@werts> wrote in message
> news:u4t8uSIOEHA.1348@TK2MSFTNGP12.phx.gbl...
> > "David F" <David-White@earthlink.net> wrote in message
> > news:pezoc.18145$Hs1.10044@newsread2.news.pas.earthlink.net...
> > > Assuming of course that the instantiation statement is ok.
> > > As a matter of fact, that very instantiation passes successfuly on
VC++
> > 7.1
> > > (and Borland) but since I was suspicious that it was OK there "more by
> > luck
> > > than brain", I checked the same on Linux\GNU were the instantiation
> > failed.
> > >
> > > This question is more for people who know well the C++ ISO standard,
in
> > the
> > > chapter on template. My hunch is that the problem is with the language
> > spec.
> > >
> > > Thanks
> >
> > I'm not sure if I understand you right. It's not only possible, it's
> common:
> >
> > template<class B> struct D
> > {
> > void D() { B::C(); }
> > };
> >
> > This will fail to compile on the instantiation if, and only if, B has no
> > member C() that has either none or all default parameters.
> >
> > So:
> >
> > struct E: D<E> { int C(); }; // fine
> > struct F: D<F> {}; // oops
> >
> > S.
> >
> >
>
>



Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by Arnaud

Arnaud
Thu May 13 01:29:20 CDT 2004

David F wrote:
> There was no intention to trick with the question.
> Nor was it intended to relate to some too trivial cases as you
> brought up. So please read it again.
> I did write that it passes successfully two compilers and I don't
> think that it would if there would be such a trivial mistake on the
> programmer's part as you described.
> Regretfully, for commercial reasons, I am not at liberty to publish
> the code, not even the very few lines that demonstrate the problem.

Can you check your code against Comeau online?
What does this code imply? Koenig lookup? 2-phase lookup? Give us a hint, or
try to write a sample that reproduce the behaviour, because we can't help
you if you aren't more specific!

Arnaud
MVP - VC



Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by tom_usenet

tom_usenet
Thu May 13 09:54:08 CDT 2004

On Thu, 13 May 2004 00:23:49 GMT, "David F"
<David-White@earthlink.net> wrote:

What do you mean by a "compilable template definition"?

>Assuming of course that the instantiation statement is ok.

What do you mean by "the instantiation statement is ok"?

>As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
>(and Borland) but since I was suspicious that it was OK there "more by luck
>than brain", I checked the same on Linux\GNU were the instantiation failed.
>
>This question is more for people who know well the C++ ISO standard, in the
>chapter on template. My hunch is that the problem is with the language spec.

I'm forced to make some assumptions. By "compilable template
definition" you mean that if you don't have any instantiations of the
template, it compiles ok. By "the instantiation statement" I'll assume
you mean a statement that referencing the "compilable template
definition" either in an implicit or explicit instantiation. I'm not
sure what you mean by "is ok", since you then say that it won't
compile under Linux/GNU.

Assuming that, if the instantiation "is ok" on VC++ 7.1 but fails on
GCC, it might mean that the code contains something non-standard that
gets past the slightly more permissive syntax that VC 7.1 accepts. Or
it could be a bug in GCC. Or something completely different.

But for some odd reason you haven't posted the error that GCC gives
you or the code in question! We're not psychic...

Now, as for compiling a template definition, until it is instantiated
only minimal compilation occurs, particularly with MSVC++ which
doesn't have two phase name lookup implemented. Nor does GCC I think,
but you can try Comeau C++ which does. This means that it will try to
compile what it can - everything that doesn't depend on the template
parameter(s).

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by Carl

Carl
Thu May 13 11:10:07 CDT 2004

David F wrote:
> Assuming of course that the instantiation statement is ok.
> As a matter of fact, that very instantiation passes successfuly on
> VC++ 7.1 (and Borland) but since I was suspicious that it was OK
> there "more by luck than brain", I checked the same on Linux\GNU were
> the instantiation failed.
>
> This question is more for people who know well the C++ ISO standard,
> in the chapter on template. My hunch is that the problem is with the
> language spec.

It's entirely possible for a template to fail on instantiation. If it
succeeds on one compiler and fails on another, then it could be a bug in
either compiler or in your code. If you can't post code, try
http://www.comeaucomputing.com/tryitout/. Generally Comeau is regarded as
being as close as we have to a "gold standard" for language conformance.

-cd



Re: Is it possible therotically,that a compilable template definition will fail just on instatiation?! by Hendrik

Hendrik
Mon May 17 05:42:28 CDT 2004

David F <David-White@earthlink.net> wrote:
> Assuming of course that the instantiation statement is ok.
> As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
> (and Borland) but since I was suspicious that it was OK there "more by luck
> than brain", I checked the same on Linux\GNU were the instantiation failed.
>
> This question is more for people who know well the C++ ISO standard, in the
> chapter on template. My hunch is that the problem is with the language spec.

I am not sure what you are getting at. Can't
you provide an example (preferably with all
error messages)?

VC and (I think) Borland don't implement so
called two-phase name lookup. As a result,
template code is not syntax-checked at all
until it gets instanciated. I am not sure
whether current GCC versions do two-phase
lookup, but others, like CodeWarrior and
Comeau do.
As a result, I try to compile any template
code with either of these two before I check
it in, even if it will only ever be used on
VC.

> Thanks


HTH,

Schobi

--
SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers



Re: Is it possible therotically,that a compilable...?! FYI all responders by David

David
Wed May 19 16:55:39 CDT 2004

Your assumptions were all correct. The "odd reason" is not so odd. It is
simply my mistake and shame on me that I have not posted at least GNU's
error message which I do now:

/tmp/cckJIUHA.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status


My understanding is that the failure occurs at the linking phase, but due to
an error in the compilation phase.

I have a class template with n variables, all participating in a symmetrical
manner in the definition of the one member of the class.
The whole concept is meaningful only for n>=2 where n is the number of the
templates parameters. I will also try to show what I hope I can show of the
class template:

template<typename T1, typename T2, ...> class X {

a_symmetric_construct_composed_of_Ti member;
};

int main() {
X Xi;
return 0;
}

GNU fails of course only when the instantiating statement "X Xi;" is
present. Now hear this about VC++7.1/Borland:
With these compilers, the whole thing, including instantiation and even
actually using and testing the instantiated objects Xi with some follow-up
code it always succeeds when n can satisfy the equation n = k!, for any
integer k where k! means k factorial....
So in the simple case of 2, life are particularly simple because 2 = 2!...
It will next work ok if n=6 because 3! = 6, etc.
I did not deduct my suspicious in the C++ definition from those numbers but
rather the other way around! That is, from the hunch I had about the specs,
I went to check the n = k! cases and found out that indeed in these cases it
succeeds (on MS/Borland) and ONLY on these. Whenever i tried for n = 3, 4,5,
7 etc, it indeed failed.
Is not this something?

To remind you, GNU fails for any n, which from the hunch I have, is more
understandable...

As far as the Comeau C++ compiler, since the tryout does not go beyond the
compilation phase, it serves no purpose in this case.

I am not familiar with the C++ standard but I am going to read it and give
it a try. I usually shy away from documments of that style since they are
written in a cryptic style. Even though it is not driven by the same morbid
reasons physicians still write in Latin and the way lawyers phrase laws,
results are somewhat similar...

David






"tom_usenet" <tom_usenet@hotmail.com> wrote in message
news:mf27a09gv018buphab9g8c519totln3oaq@4ax.com...
> On Thu, 13 May 2004 00:23:49 GMT, "David F"
> <David-White@earthlink.net> wrote:
>
> What do you mean by a "compilable template definition"?
>
> >Assuming of course that the instantiation statement is ok.
>
> What do you mean by "the instantiation statement is ok"?
>
> >As a matter of fact, that very instantiation passes successfuly on VC++
7.1 (and Borland) but since I was suspicious that it was OK there "more by
luck
> >than brain", I checked the same on Linux\GNU were the instantiation
failed.
> >
> >This question is more for people who know well the C++ ISO standard, in
the chapter on template. My hunch is that the problem is with the language
spec.
>
> I'm forced to make some assumptions. By "compilable template definition"
you mean that if you don't have any instantiations of the
> template, it compiles ok. By "the instantiation statement" I'll assume you
mean a statement that referencing the "compilable template
> definition" either in an implicit or explicit instantiation. I'm not sure
what you mean by "is ok", since you then say that it won't compile under
Linux/GNU.
>
> Assuming that, if the instantiation "is ok" on VC++ 7.1 but fails on GCC,
it might mean that the code contains something non-standard that
> gets past the slightly more permissive syntax that VC 7.1 accepts. Or it
could be a bug in GCC. Or something completely different.
>
> But for some odd reason you haven't posted the error that GCC gives you or
the code in question! We're not psychic...
>
> Now, as for compiling a template definition, until it is instantiated only
minimal compilation occurs, particularly with MSVC++ which
> doesn't have two phase name lookup implemented. Nor does GCC I think, but
you can try Comeau C++ which does. This means that it will try to
> compile what it can - everything that doesn't depend on the template
parameter(s).
>
> Tom
> --
> C++ FAQ: http://www.parashift.com/c++-faq-lite/
> C FAQ: http://www.eskimo.com/~scs/C-faq/top.html




Re: Is it possible therotically,that a compilable...?! FYI all responders by Carl

Carl
Wed May 19 17:27:26 CDT 2004

David F wrote:

> As far as the Comeau C++ compiler, since the tryout does not go
> beyond the compilation phase, it serves no purpose in this case.

Actually, Comeau doesn't need to link to diagnose this type of error. By
default the online tryout uses -tused, which instantiates any used
templates. If there are errors, it'll report them.

>
> I am not familiar with the C++ standard but I am going to read it and
> give it a try. I usually shy away from documments of that style since
> they are written in a cryptic style.

Skip the standard and get "C++ Templates The Complete Guide" by Daveed
Vandevoorde & Nicolai Josuttis.

-cd