RE: [ROOT] Rootcint + namespace + templated classes.

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Jan 30 2003 - 22:26:54 MET


Hi Brett,

> And the errors I get are:
> Error: no such template Marshal<void> FILE:Test.h LINE:54

I can not reproduce those errors (with icc and gcc 2.96) with the CVS head.

> I find that I can make rootcint's error go away by explicitly using
> the NS:: prefix in the definition of "Something" (even though it is
> inside the namespace already):

The only (related) problem I could find, it was CINT seems to not pull in
the template definition into the global namespace following a 'using
namespace NS;' statement.

> root [2] mc->something.no_op()
> Error: class,struct,union or type NS not defined  FILE:/tmp/IBmZgC_cint
LINE:1
> *** Interpreter error recovered ***

If the linkdef file attached to your mail reflects what you tried, then this
is normal in the sense that you did not generate the dictionary from the
namespace NS (and for the needed templates).

Note a change in behavior since 3.04.  Before that release
	#pragma link C++ class MyClass;
would provoke (in some cases) the linking of templates and namespace being
instantiated/used by MyClass (i.e. something<void> in your case).  This
behavior was changed because it was too erratic and sometimes to broad
stroking.

Since 3.04,
	#pragma link C++ class MyClass;
only create the dictionary entry for MyClass.  You need to add new 'pragma'
link for the templated class that might be needed.

Cheers,
Philippe

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Brett Viren
Sent: Thursday, January 30, 2003 2:10 PM
To: ROOT-TALK ML
Subject: [ROOT] Rootcint + namespace + templated classes.


Hi,

I am trying to run rootcint on some 3rd party library code which is
fairly heavily templated and in its own namespace.  Rootcint is
failing to process it and I am wondering if it is a shortcoming or if
the code might actually be wrong C++.  I have been able to excerpt a
relatively small part to demonstrate the problem (files attached) and
give some (longish) details below:


I am running rootcint like:

shell> rootcint -v4 -f TestCint.cc -c  -I. -D_REENTRANT -I$ROOTSYS/include
Test.h TestLinkdef.h

And the errors I get are:

Error: no such template Marshal<void> FILE:Test.h LINE:54
Error: no such template Marshal<void> FILE:Test.h LINE:54


This "Marshal" class shows up as a default template parameter in the
main class I want to use (called "Something"):

	namespace NS {
	//...
	template <class R,class Marsh=Marshal<R> >
	class Something
	{
	public:
	    Something() {}
	    ~Something() {}
	    void no_op() {}
	};
	//...
	}


I then try to use this "Something" class as a data member in my own
class which I want rootcint to process:


	class MyClass
	{
	public:
	    MyClass();
	    ~MyClass();
	    NS::Something<void> something;
	};


I find that I can make rootcint's error go away by explicitly using
the NS:: prefix in the definition of "Something" (even though it is
inside the namespace already):

	template <class R,class Marsh=NS::Marshal<R> >

However, since this code is actually from a 3rd party library, I
don't want to have to edit (unless it is just bad C++, then I'll
submit a bug report).

I can also stop the errors by adding "using namespace NS" just before
the definition of MyClass, but I still *must* use the "NS::" preface
to the "something" declaration.  Also, while going this route does let
me create a root-ified library with MyClass, when trying to access the
"something" member from inside ROOT I get an error about the NS
namespace being unkown:


root [0] gSystem->Load("libTest.so")
root [1] MyClass* mc = new MyClass
root [2] mc->something.no_op()
Error: class,struct,union or type NS not defined  FILE:/tmp/IBmZgC_cint
LINE:1
*** Interpreter error recovered ***



This is on the edge of what I know about C++.  Should Rootcint be able
to handle this code, or is it incorrect C++? (G++ 3.2 compiles it
w/out warnings with -Wall and -pedantic).

I am using CVS Version 3.05/01 29 January 2003 on Debian x86, GCC 3.2.

I'll attach the Test.h and TestLinkdef.h and the generated
TestCint.{cc,h} files


Thanks,
-Brett.



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET