This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

C++ PATCH: PR 21340


This patch fixes a problem with the lazy implicit function machinery
that I added for 4.0.  In particular, if we did a lookup from a
template context that causes us to lazily declare an implicit
function, we were forgetting that the lazy declaration is not itself
in the template.

Tested on x86_64-unknown-linux-gnu; applied to the mainline and to the
4.0 branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-05-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/21340
	* method.c (implicitly_declare_fn): Clear processing_template_decl
	when generating implicit declaration.

2005-05-28  Mark Mitchell  <mark@codesourcery.com>

	PR c++/21340
	* g++.dg/init/ctor6.C: New test.

Index: gcc/cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.329
diff -c -5 -p -r1.329 method.c
*** gcc/cp/method.c	25 May 2005 22:08:21 -0000	1.329
--- gcc/cp/method.c	29 May 2005 00:02:12 -0000
*************** implicitly_declare_fn (special_function_
*** 966,975 ****
--- 966,988 ----
    tree return_type;
    tree fn_type;
    tree raises = empty_except_spec;
    tree rhs_parm_type = NULL_TREE;
    tree name;
+   HOST_WIDE_INT saved_processing_template_decl;
+ 
+   /* Because we create declarations for implictly declared functions
+      lazily, we may be creating the declaration for a member of TYPE
+      while in some completely different context.  However, TYPE will
+      never be a dependent class (because we never want to do lookups
+      for implicitly defined functions in a dependent class).
+      Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
+      because we only create clones for constructors and destructors
+      when not in a template.  */
+   gcc_assert (!dependent_type_p (type));
+   saved_processing_template_decl = processing_template_decl;
+   processing_template_decl = 0;
  
    type = TYPE_MAIN_VARIANT (type);
  
    if (targetm.cxx.cdtor_returns_this () && !TYPE_FOR_JAVA (type))
      {
*************** implicitly_declare_fn (special_function_
*** 1064,1073 ****
--- 1077,1089 ----
    DECL_NOT_REALLY_EXTERN (fn) = 1;
    DECL_DECLARED_INLINE_P (fn) = 1;
    DECL_INLINE (fn) = 1;
    gcc_assert (!TREE_USED (fn));
  
+   /* Restore PROCESSING_TEMPLATE_DECL.  */
+   processing_template_decl = saved_processing_template_decl;
+ 
    return fn;
  }
  
  /* Add an implicit declaration to TYPE for the kind of function
     indicated by SFK.  Return the FUNCTION_DECL for the new implicit
Index: gcc/testsuite/g++.dg/init/ctor6.C
===================================================================
RCS file: gcc/testsuite/g++.dg/init/ctor6.C
diff -N gcc/testsuite/g++.dg/init/ctor6.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/init/ctor6.C	29 May 2005 00:02:12 -0000
***************
*** 0 ****
--- 1,20 ----
+ // PR c++/21340
+ 
+ struct Base{};
+ struct Iterator : virtual Base {};
+ bool operator==(const Iterator&, const Iterator&);
+ struct IteratorI : Iterator {};
+ struct Obj
+ {
+   bool operator==(const Obj&) const;
+ };
+ template <int>bool dummy()
+ {
+   Obj lhs, rhs;
+   return lhs == rhs;
+ }
+ int
+ main(int argc, char** argv)
+ {
+   IteratorI* it2 = new IteratorI();
+ }


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