This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Experienced something when using C++ template. A possible compiler/linker bug?

hello,

just now, I am implementing a CircularQueue template on my code (this class template works fine on a PC-based C++ compiler). I am using Code Composer Studio  Version: 5.1.1.00031 .

==========================

on file circularqueue.hpp, contains the template:

template <class datatype,class ctrtype> class CircularQueue
{
private:
........

public:
    CircularQueue(ctrtype   queuesize);
    ~CircularQueue(void);
.....
};

=======================

on file circularqueue.cpp, contains the implementation

template <class datatype,class ctrtype> CircularQueue <datatype,ctrtype> ::CircularQueue(ctrtype  queuesize)
{
..... codes
}

====================

on file ut.cpp  (for unittest), contains

void testcasequeue()

{

CircularQueue<int,int> q(3);

.... code and asserts blah blah

}

when I try to compile this, this gives me an error:

<Linking>

 undefined                                                                                                        first referenced       
  symbol                                                                                                              in file            
 ---------                                                                                                        ----------------       
 bool CircularQueue<T1, T2>::Dequeue(T1 *) [with T1=unsigned char, T2=unsigned char]                              ./SourceCodes/Ut/ut.obj
 void CircularQueue<T1, T2>::Enqueue(T1) [with T1=unsigned char, T2=unsigned char]                                ./SourceCodes/Ut/ut.obj
 bool CircularQueue<T1, T2>::HasData() [with T1=unsigned char, T2=unsigned char]                                  ./SourceCodes/Ut/ut.obj
 CircularQueue<T1, T2>::CircularQueue<unsigned char, unsigned char>(T2) [with T1=unsigned char, T2=unsigned char] ./SourceCodes/Ut/ut.obj
 CircularQueue<T1, T2>::~CircularQueue<unsigned char, unsigned char>() [with T1=unsigned char, T2=unsigned char]  ./SourceCodes/Ut/ut.obj

error #10234-D: unresolved symbols remain
error #10010: errors encountered during linking;

===================================

but when I just put add dummy function on circularqueue.cpp  (and it's not used elsewhere)

void dummyfunc()

{

CircularQueue<int,int> q(3); // when I comment this, the linker throws an error

}

then everything works fine. I can upload the program to the MSP430 and it runs happily.  do I miss some compiler settings for this? I would like to remove the dummy function as this should not be there in the first place. 

My guess it that there is some unwanted dead-code removal process that takes place during compiling?

thanks ;)