This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][C++] Fix PR39242
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 20 Feb 2009 10:23:08 +0100 (CET)
- Subject: [PATCH][C++] Fix PR39242
This avoids instantiating extern but not inline declared functions which
fixes Yast YCP compilation.
The patch has slight positive effect on memory-usage and binary size of
the set of C++ testcases run by gcc.opensuse.org.
Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for trunk?
Thanks,
Richard.
2009-02-20 Richard Guenther <rguenther@suse.de>
PR c++/39242
* pt.c (instantiate_decl): Do not instantiate extern, non-inline
declared functions.
* g++.dg/template/instantiate10.C: New testcase.
Index: gcc/cp/pt.c
===================================================================
*** gcc/cp/pt.c (revision 144292)
--- gcc/cp/pt.c (working copy)
*************** instantiate_decl (tree d, int defer_ok,
*** 15283,15291 ****
/* In general, we do not instantiate such templates... */
if (external_p
/* ... but we instantiate inline functions so that we can inline
! them and ... */
&& ! (TREE_CODE (d) == FUNCTION_DECL
! && possibly_inlined_p (d))
/* ... we instantiate static data members whose values are
needed in integral constant expressions. */
&& ! (TREE_CODE (d) == VAR_DECL
--- 15283,15296 ----
/* In general, we do not instantiate such templates... */
if (external_p
/* ... but we instantiate inline functions so that we can inline
! them. An explicit instantiation declaration prohibits implicit
! instantiation of non-inline functions. With high levels of
! optimization, we would normally inline non-inline functions
! -- but we're not allowed to do that for "extern template" functions.
! Therefore, we check DECL_DECLARED_INLINE_P, rather than
! possibly_inlined_p. And ... */
&& ! (TREE_CODE (d) == FUNCTION_DECL
! && DECL_DECLARED_INLINE_P (d))
/* ... we instantiate static data members whose values are
needed in integral constant expressions. */
&& ! (TREE_CODE (d) == VAR_DECL
Index: gcc/testsuite/g++.dg/template/instantiate10.C
===================================================================
*** gcc/testsuite/g++.dg/template/instantiate10.C (revision 0)
--- gcc/testsuite/g++.dg/template/instantiate10.C (revision 0)
***************
*** 0 ****
--- 1,37 ----
+ /* PR c++/39242, xplicit instantiation declaration prohibits implicit
+ instantiation of non-inline functions. */
+ /* { dg-do compile } */
+ /* { dg-options "-O" } */
+
+ class Rep {
+ public:
+ void unref() const { }
+ static void unref (const Rep * obj_r) { obj_r->unref(); }
+ };
+ template<typename _Tp, typename _Bt = _Tp>
+ class RepPtrStore {
+ _Tp * _obj;
+ void _assign( _Tp * new_r );
+ public:
+ ~RepPtrStore() { _assign( 0 ); }
+ };
+ template<typename _Tp,typename _Bt>
+ void RepPtrStore<_Tp,_Bt>::_assign( _Tp * new_r )
+ {
+ Rep::unref( _obj );
+ }
+ class RepPtrBase { };
+ template<typename _Bt> class PtrBase : public RepPtrBase { };
+ template<typename _Tp, typename _Bt = _Tp>
+ class Ptr : public PtrBase<_Bt> {
+ RepPtrStore<_Tp,_Bt> _ptr;
+ };
+ class YCode;
+ class YStatement;
+ typedef Ptr<YStatement,YCode> YStatementPtr;
+ extern template class RepPtrStore<YStatement,YCode>;
+ class ExecutionEnvironment {
+ YStatementPtr m_statement;
+ ~ExecutionEnvironment() { };
+ };
+