473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can a successfully compileable template definition fail on instantiation?

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
Jul 22 '05 #1
2 1510
David wrote:
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?

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #2
ag******@yahoo.com (David) wrote in message news:<b6**************************@posting.google. com>...
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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
7
by: Andrew Ward | last post by:
Hi All, Considering the following code: struct A; struct B { std::list<A> l; };
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
3
by: Patrick Guio | last post by:
Hi, I have trouble to compile the following piece of code with g++3.4 but not with earlier version // Foo.h template<typename T> class Foo { public:
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
5
by: lobequadrat | last post by:
Hello, I am trying to get the following code work (unfortunately not mine ... :( ) template <class Tclass Test { public: class ELEM;
8
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a...
9
by: subramanian100in | last post by:
Consider the following program: #include <iostream> #include <string> #include <vector> using namespace std; template<class Tclass Vec : public vector<T> {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.