This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How do I manually instantiate template functions with -fno-implicit-templates


>>>>> Alexandre Oliva <oliva@dcc.unicamp.br> writes:

Alexandre> Mark Johnstone writes:
>> Using egcs 1.0.X how do I manually instantiate template functions
>> when I'm using -fno-implicit-templates, now that guiding decls have
>> been removed?

>> template void foo (bar a, baz b);

Alexandre> template void foo<> (bar a, baz b);

Alexandre> ... should do.

Alexandre> -- Alexandre Oliva mailto:oliva@dcc.unicamp.br
Alexandre> mailto:aoliva@acm.org http://www.dcc.unicamp.br/~oliva
Alexandre> Universidade Estadual de Campinas, SP, Brasil

Here is a test case for what I need:

test.h:

#include<iostream.h>

struct test_box
    {
    void print(void) {cout << "this is a test" << endl;}
    };

void test(test_box *);  // Just a forward declaration


test.C:

#include "test.h"

template <class BOX> void test(BOX *the_box)
    {
    the_box->print();
    };

template void test<> (test_box *);  // This is the guiding decl


main.C:

#include "test.h"

main()
    {
    test_box box1;
    test(&box1);
    }


Here is what happens when I compile this code:

pita:~/tmp> g++ -v
Reading specs from /home/markj/lib/gcc-lib/rs6000-ibm-aix3.2.5/egcs-2.91.02/specs
gcc version egcs-2.91.02 971216 (gcc-2.8.0)

pita:~/tmp> g++ -c -fno-implicit-templates test.C

pita:~/tmp> g++ -fno-implicit-templates test.o main.C
/home/markj/tmp/cceUFtMa1.o(.pr+0x20):main.C: undefined reference to `test(test_box *)'
collect2: ld returned 1 exit status

pita:~/tmp> g++ -c -fno-implicit-templates -fguiding-decls test.C

pita:~/tmp> g++ -fno-implicit-templates test.o main.C

pita:~/tmp> a.out
this is a test

Note that I configured g++ with --with-gnu-ld
Our version of gnu ld is:

pita:~/tmp> gnu-ld -v
GNU ld version 2.8.1 (with BFD 2.8.1)

If that makes any difference.

Again, thanks in advance for any advice you can give.

-- 

Mark S. Johnstone, Ph.D.  Methodology and Tools Development
markj@ibmoto.com          Networking & Computing Systems Group
                          Somerset Design Center, MD: OE70
(512) 424-8468 (desk)     6200 Bridgepoint Parkway, Bldg. #4, Austin, TX  78730
(512) 933-7333 pin 428468 (pager)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]