This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] _GLIBCPP_EXTERN_TEMPLATE
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 13 Feb 2003 15:28:26 -0600
- Subject: [v3] _GLIBCPP_EXTERN_TEMPLATE
This adds a new macro, _GLIBCPP_EXTERN_TEMPLATE, and guards the use of
"extern template" in the libstdc++ includes.
tested x86/linux
2003-02-13 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/c++config (_GLIBCPP_EXTERN_TEMPLATE): Define.
* include/bits/basic_ios.tcc: Guard use of extern template.
* include/std/std_iomanip.h: Same.
* include/bits/streambuf.tcc: Same.
* include/bits/stl_alloc.h: Same.
* include/bits/locale_facets.tcc: Same.
* include/bits/ostream.tcc: Same.
* include/bits/istream.tcc: Same.
* include/bits/fstream.tcc: Same.
* include/bits/basic_string.tcc: Same.
Index: include/bits/basic_ios.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_ios.tcc,v
retrieving revision 1.17
diff -c -p -r1.17 basic_ios.tcc
*** include/bits/basic_ios.tcc 1 Nov 2002 17:30:35 -0000 1.17
--- include/bits/basic_ios.tcc 13 Feb 2003 21:26:20 -0000
***************
*** 1,6 ****
// basic_ios locale and locale-related member functions -*- C++ -*-
! // Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,6 ----
// basic_ios locale and locale-related member functions -*- C++ -*-
! // Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
*************** namespace std
*** 186,195 ****
--- 186,197 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_ios<char>;
#ifdef _GLIBCPP_USE_WCHAR_T
extern template class basic_ios<wchar_t>;
+ #endif
#endif
} // namespace std
Index: include/bits/basic_string.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/basic_string.tcc,v
retrieving revision 1.30
diff -c -p -r1.30 basic_string.tcc
*** include/bits/basic_string.tcc 16 Jan 2003 03:11:13 -0000 1.30
--- include/bits/basic_string.tcc 13 Feb 2003 21:26:20 -0000
***************
*** 1,6 ****
// Components for manipulating sequences of characters -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// Components for manipulating sequences of characters -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
*************** namespace std
*** 933,938 ****
--- 933,939 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_string<char>;
extern template
basic_istream<char>&
*************** namespace std
*** 961,966 ****
--- 962,968 ----
extern template
basic_istream<wchar_t>&
getline(basic_istream<wchar_t>&, wstring&);
+ #endif
#endif
} // namespace std
Index: include/bits/c++config
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/c++config,v
retrieving revision 1.635
diff -c -p -r1.635 c++config
*** include/bits/c++config 13 Feb 2003 00:17:06 -0000 1.635
--- include/bits/c++config 13 Feb 2003 21:26:20 -0000
***************
*** 1,6 ****
// Predefined symbols and macros -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,7 ----
// Predefined symbols and macros -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
! // Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
***************
*** 36,43 ****
// The current version of the C++ library in compressed ISO date format.
#define __GLIBCPP__ 20030213
! // This is necessary until GCC supports separate template
! // compilation.
#define _GLIBCPP_NO_TEMPLATE_EXPORT 1
// This is a hack around not having either pre-compiled headers or
--- 37,43 ----
// The current version of the C++ library in compressed ISO date format.
#define __GLIBCPP__ 20030213
! // This is necessary until GCC supports separate template compilation.
#define _GLIBCPP_NO_TEMPLATE_EXPORT 1
// This is a hack around not having either pre-compiled headers or
***************
*** 48,53 ****
--- 48,63 ----
// member functions are only declared, and definitions are not parsed
// by the compiler, but instead instantiated into the library binary.
#define _GLIBCPP_FULLY_COMPLIANT_HEADERS 1
+
+ // Allow use of the GNU syntax extension, "extern template." This
+ // extension is fully documented in the g++ manual, but in a nutshell,
+ // it inhibits all implicit instantiations and is used throughout the
+ // library to avoid multiple weak definitions for required types that
+ // are already explicitly instantiated in the library binary. This
+ // substantially reduces the binary size of resulting executables.
+ #ifndef _GLIBCPP_EXTERN_TEMPLATE
+ #define _GLIBCPP_EXTERN_TEMPLATE 1
+ #endif
// To enable older, ARM-style iostreams and other anachronisms use this.
//#define _GLIBCPP_DEPRECATED 1
Index: include/bits/fstream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/fstream.tcc,v
retrieving revision 1.48
diff -c -p -r1.48 fstream.tcc
*** include/bits/fstream.tcc 11 Feb 2003 19:53:51 -0000 1.48
--- include/bits/fstream.tcc 13 Feb 2003 21:26:20 -0000
*************** namespace std
*** 505,510 ****
--- 505,511 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_filebuf<char>;
extern template class basic_ifstream<char>;
extern template class basic_ofstream<char>;
*************** namespace std
*** 515,520 ****
--- 516,522 ----
extern template class basic_ifstream<wchar_t>;
extern template class basic_ofstream<wchar_t>;
extern template class basic_fstream<wchar_t>;
+ #endif
#endif
} // namespace std
Index: include/bits/istream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/istream.tcc,v
retrieving revision 1.38
diff -c -p -r1.38 istream.tcc
*** include/bits/istream.tcc 16 Jan 2003 20:30:22 -0000 1.38
--- include/bits/istream.tcc 13 Feb 2003 21:26:22 -0000
***************
*** 1,6 ****
// istream classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// istream classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
*************** namespace std
*** 1189,1194 ****
--- 1189,1195 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_istream<char>;
extern template istream& ws(istream&);
extern template istream& operator>>(istream&, char&);
*************** namespace std
*** 1203,1207 ****
--- 1204,1209 ----
extern template wistream& ws(wistream&);
extern template wistream& operator>>(wistream&, wchar_t&);
extern template wistream& operator>>(wistream&, wchar_t*);
+ #endif
#endif
} // namespace std
Index: include/bits/locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/locale_facets.tcc,v
retrieving revision 1.89
diff -c -p -r1.89 locale_facets.tcc
*** include/bits/locale_facets.tcc 11 Feb 2003 21:55:48 -0000 1.89
--- include/bits/locale_facets.tcc 13 Feb 2003 21:26:24 -0000
*************** namespace std
*** 2219,2224 ****
--- 2219,2225 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class moneypunct<char, false>;
extern template class moneypunct<char, true>;
extern template class moneypunct_byname<char, false>;
*************** namespace std
*** 2471,2476 ****
--- 2472,2478 ----
extern template
bool
has_facet<messages<wchar_t> >(const locale&);
+ #endif
#endif
} // namespace std
Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.35
diff -c -p -r1.35 ostream.tcc
*** include/bits/ostream.tcc 13 Feb 2003 17:43:58 -0000 1.35
--- include/bits/ostream.tcc 13 Feb 2003 21:26:25 -0000
*************** namespace std
*** 701,706 ****
--- 701,707 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_ostream<char>;
extern template ostream& endl(ostream&);
extern template ostream& ends(ostream&);
*************** namespace std
*** 721,725 ****
--- 722,727 ----
extern template wostream& operator<<(wostream&, char);
extern template wostream& operator<<(wostream&, const wchar_t*);
extern template wostream& operator<<(wostream&, const char*);
+ #endif
#endif
} // namespace std
Index: include/bits/stl_alloc.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/stl_alloc.h,v
retrieving revision 1.28
diff -c -p -r1.28 stl_alloc.h
*** include/bits/stl_alloc.h 23 Jan 2003 17:21:10 -0000 1.28
--- include/bits/stl_alloc.h 13 Feb 2003 21:26:26 -0000
*************** namespace std
*** 898,906 ****
--- 898,908 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class allocator<char>;
extern template class allocator<wchar_t>;
extern template class __pool_alloc<true,0>;
+ #endif
} // namespace std
#endif
Index: include/bits/streambuf.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/streambuf.tcc,v
retrieving revision 1.24
diff -c -p -r1.24 streambuf.tcc
*** include/bits/streambuf.tcc 11 Feb 2003 09:59:19 -0000 1.24
--- include/bits/streambuf.tcc 13 Feb 2003 21:26:26 -0000
***************
*** 1,6 ****
// Stream buffer classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// Stream buffer classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
*************** namespace std
*** 245,250 ****
--- 245,251 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template class basic_streambuf<char>;
extern template
streamsize
*************** namespace std
*** 257,262 ****
--- 258,264 ----
streamsize
__copy_streambufs(basic_ios<wchar_t>&, basic_streambuf<wchar_t>*,
basic_streambuf<wchar_t>*);
+ #endif
#endif
} // namespace std
Index: include/std/std_iomanip.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_iomanip.h,v
retrieving revision 1.6
diff -c -p -r1.6 std_iomanip.h
*** include/std/std_iomanip.h 21 Nov 2002 07:06:40 -0000 1.6
--- include/std/std_iomanip.h 13 Feb 2003 21:26:27 -0000
***************
*** 1,6 ****
// Standard stream manipulators -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
--- 1,7 ----
// Standard stream manipulators -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003
! // Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
*************** namespace std
*** 265,270 ****
--- 266,272 ----
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.
+ #if _GLIBCPP_EXTERN_TEMPLATE
extern template ostream& operator<<(ostream&, _Setfill<char>);
extern template ostream& operator<<(ostream&, _Setiosflags);
extern template ostream& operator<<(ostream&, _Resetiosflags);
*************** namespace std
*** 291,296 ****
--- 293,299 ----
extern template wistream& operator>>(wistream&, _Setbase);
extern template wistream& operator>>(wistream&, _Setprecision);
extern template wistream& operator>>(wistream&, _Setw);
+ #endif
#endif
} // namespace std