namespaces and explicit instantiation

Kurt Garloff garloff@student.physik.uni-dortmund.de
Mon Jun 29 05:19:00 GMT 1998


Hi,

here come a few problems with namespaces.
---
/* bug_ns2.cc */
/* Demo to show namespace bugs of egcs-980621 */

namespace NS
{
template <typename T>
class Vector;
template <typename T>
char solver (Vector<T>& v);
}

namespace NS
{
template <typename T>
char do_solve (Vector<T>& v)
{
   return solver (v);
};

template char do_solve <double> (Vector<double> &);
}
---
Here is what the compiler produces:
garloff@student:~/numerix/lina/test $ egcc -v
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.42/specs
gcc version egcs-2.91.42 19980621 (gcc2 ss-980502 experimental)
garloff@student:~/numerix/lina/test $ egcc -c bug_ns2.cc
garloff@student:~/numerix/lina/test $ nm bug_ns2.o | c++filt
00000000 ? __FRAME_BEGIN__
00000000 T char NS::do_solve<double>(NS::Vector<double> &)
00000000 t gcc2_compiled.
         U char solver<double>(NS::Vector<double> &)    
	 
	 
The last line should read
         U char NS:solver<double>(NS::Vector)<double> &)

solver() is defined in another file and explicitly instantiated:
namespace NS
{
   
template Vector <double>;
template char solver <double> (Vector<double> &);
}

garloff@student:~/numerix/lina/test $ nm bug_ns.o | c++filt
00000000 ? __FRAME_BEGIN__
00000000 T Vector<double>::Vector(void)
00000000 t gcc2_compiled.
00000014 T char NS::solver<double>(NS::Vector<double> &)

Here the name of solver is composed correctly.
However, the second line is wrong. It should read
00000000 T NS:Vector<double>::Vector(void)

The result of the above errors is that files using namespaces won't link
together. The missing NS before the member functions/operators of class
Vector are consistent, so it does not cause linker errors (as long as there
are no name conflict with objects from other namespaces), but the solver ()
will prevent anything from successfully linking.

-- 
Kurt Garloff
<K.Garloff@ping.de>




More information about the Gcc-bugs mailing list