Can a successfully compileable template definition fail on instantiation?

D

David

Assuming of course that the instantiation statement is 100% 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, the
chapter on templates. My hunch is that the problem is with the language spec.

Thanks
 
A

Andrey Tarasevich

David said:
Assuming of course that the instantiation statement is 100% 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, the
chapter on templates. My hunch is that the problem is with the
language spec.

Why don't you just post some minimal piece of code that reproduces the
problem?
 
M

Michiel Salters

Assuming of course that the instantiation statement is 100% 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.

Yes, and this is in fact a very common technique. For instance,
std::vector<T>::vector( size_type, T const& = T(), {default allocator} )

It is impossible to instantiate this member when only the size_type
argument is provided and T doesn't have an accessible default ctor.

Basically templates compile if there is at least one set of arguments
for which they can be instantiated. The reverse is not true; some
errors are too hard to detect without instantiating.

E.g. a template with unsigned integer parameters A,B,C and N that
could only compile if A^(N+3)+B^(N+3)==C^(N+3). A compiler may
reject this, because there is no set of arguments for which this holds
but it isn't required to be aware of the proof to Fermats theorem.
It may instead reject every attempt to instantiate.

Regards,
Michiel Salters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,999
Latest member
MakersCBDGummiesReview

Latest Threads

Top