opt must be one of the following values.
Table A–21 The -template Values|
Value |
Meaning |
|---|---|
|
[no%]extdef |
[Do not] Search for template definitions in separate source files. |
|
[no%]geninlinefuncs |
[Do not] Generate unreferenced inline member functions for explicitly instantiated class templates. |
|
[no%]wholeclass |
[Do not] Instantiate a whole template class, rather than only those functions that are used. You must reference at least one member of the class; otherwise, the compiler does not instantiate any members for the class. |
If the -template option is not specified, -template=no%wholeclass,extdef is assumed.
Consider the following code:
example% cat Example.cc
template <class T> struct S {
void imf() {}
static void smf() {}
};
template class S <int>;
int main() {
}
example%
|
When you specify -template=geninlinefuncs, even though the two member functions of S are not called in the program, they are generated in the object file.
example% CC -c -template=geninlinefuncs Example.cc
example% nm -C Example.o
Example.o:
[Index] Value Size Type Bind Other Shndx Name
[5] 0 0 NOTY GLOB 0 ABS __fsr_init_value
[1] 0 0 FILE LOCL 0 ABS b.c
[4] 16 32 FUNC GLOB 0 2 main
[3] 104 24 FUNC LOCL 0 2 void S<int>::imf()
[__1cBS4Ci_Dimf6M_v_]
[2] 64 20 FUNC LOCL 0 2 void S<int>::smf()
[__1cBS4Ci_Dsmf6F_v_]
|
7.2.2 Whole-Class Instantiation, 7.5 Template Definition Searching