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]

Re: [PR c++/17788] add decl for implicit default ctor even if ill-formed


On Feb 14, 2005, Alexandre Oliva <aoliva@redhat.com> wrote:

> 	PR c++/17788
> 	* g++.old-deja/g++.bugs/900205_04.C: Adjust.

Oops, I accidentally dropped the other, new testcase from the patch.
Also, the tweak for the testcase above was what I thought the new
errors should look like, not what they actually did.

Unfortunately, it's a bit difficult to make them look exactly like I
wanted.  Here's my first take at fixing it, along with the revised
patch for the testcase.  See the comment for an explanation for the
odd placement of the first error.

Is this worth pursuing?  Should I go through the other changes in the
testsuite that are probably going to be required by this change?

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>
	* decl2.c (mark_used): Set the source location of the used decl to
	the current input location here...
	* method.c (synthesize_method): ... not here.  Set input_location
	from the decl instead.

Index: gcc/cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.765
diff -u -p -r1.765 decl2.c
--- gcc/cp/decl2.c 3 Feb 2005 10:25:52 -0000 1.765
+++ gcc/cp/decl2.c 14 Feb 2005 17:16:27 -0000
@@ -3161,9 +3161,20 @@ mark_used (tree decl)
       && DECL_ARTIFICIAL (decl) 
       && !DECL_THUNK_P (decl)
       && ! DECL_INITIAL (decl)
-      /* Kludge: don't synthesize for default args.  */
+      /* Kludge: don't synthesize for default args.  Unfortunately this
+	 rules out initializers of namespace-scoped objects too, but
+	 it's sort-of ok if the implicit ctor or dtor decl keeps
+	 pointing to the class location.  */
       && current_function_decl)
     {
+      /* Put the function definition at the position where it is needed,
+	 rather than within the body of the class.  That way, an error
+	 during the generation of the implicit body points at the place
+	 where the attempt to generate the function occurs, giving the
+	 user a hint as to why we are attempting to generate the
+	 function.  */
+      DECL_SOURCE_LOCATION (decl) = input_location;
+
       synthesize_method (decl);
       /* If we've already synthesized the method we don't need to
 	 instantiate it, so we can return right away.  */
Index: gcc/cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.321
diff -u -p -r1.321 method.c
--- gcc/cp/method.c 9 Feb 2005 02:53:37 -0000 1.321
+++ gcc/cp/method.c 14 Feb 2005 17:16:28 -0000
@@ -705,12 +705,15 @@ synthesize_method (tree fndecl)
   tree context = decl_function_context (fndecl);
   bool need_body = true;
   tree stmt;
+  location_t save_input_location = input_location;
 
   /* If we've been asked to synthesize a clone, just synthesize the
      cloned function instead.  Doing so will automatically fill in the
      body for the clone.  */
   if (DECL_CLONED_FUNCTION_P (fndecl))
     {
+      DECL_SOURCE_LOCATION (DECL_CLONED_FUNCTION (fndecl)) =
+	DECL_SOURCE_LOCATION (fndecl);
       synthesize_method (DECL_CLONED_FUNCTION (fndecl));
       return;
     }
@@ -724,13 +727,7 @@ synthesize_method (tree fndecl)
   else if (nested)
     push_function_context_to (context);
 
-  /* Put the function definition at the position where it is needed,
-     rather than within the body of the class.  That way, an error
-     during the generation of the implicit body points at the place
-     where the attempt to generate the function occurs, giving the
-     user a hint as to why we are attempting to generate the
-     function.  */
-  DECL_SOURCE_LOCATION (fndecl) = input_location;
+  input_location = DECL_SOURCE_LOCATION (fndecl);
 
   start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
   stmt = begin_function_body ();
@@ -761,6 +758,8 @@ synthesize_method (tree fndecl)
   finish_function_body (stmt);
   expand_or_defer_fn (finish_function (0));
 
+  input_location = save_input_location;
+
   if (! context)
     pop_from_top_level ();
   else if (nested)
Index: gcc/testsuite/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>
	PR c++/17788
	* g++.old-deja/g++.bugs/900205_04.C: Adjust.

Index: gcc/testsuite/g++.old-deja/g++.bugs/900205_04.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.bugs/900205_04.C,v
retrieving revision 1.4
diff -u -p -r1.4 900205_04.C
--- gcc/testsuite/g++.old-deja/g++.bugs/900205_04.C 1 May 2003 02:02:37 -0000 1.4
+++ gcc/testsuite/g++.old-deja/g++.bugs/900205_04.C 14 Feb 2005 17:16:41 -0000
@@ -9,19 +9,23 @@
 
 // keywords: default constructor, inheritance
 
-struct struct0 {
+// In ISO C++ 1998, it is not illegal to define such a class, but if
+// the implicitly-declared constructor is used, then it is
+// implicitly defined and found to be ill-formed.
+
+struct struct0 { // { dg-error "note" }
   int data_member;
 
   struct0 (int, void *);	// suppresses implicit default constructor
 };
 
-struct0::struct0 (int, void *)
+struct0::struct0 (int, void *) // { dg-error "note" }
 {
 }
 
-struct struct0_derived_struct_0 : public struct0 { // { dg-error "" } 
+struct struct0_derived_struct_0 : public struct0 { // { dg-error "" }
 };
 
-// struct0_derived_struct_0 object;	// would give g++ error if compiled
+struct0_derived_struct_0 object;
 
 int main () { return 0; }
-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}

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