public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages
@ 2010-12-09 15:33 Nathan Froyd
  2010-12-09 21:44 ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Froyd @ 2010-12-09 15:33 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason

When we're pretty-printing things in error messages, we now get confused
by the new TRANSLATION_UNIT_DECLs added this release cycle:

g++.old-deja/g++.other/overload11.C:86:13: error: no context to resolve type of '#'translation_unit_decl' not supported by dump_decl#<declaration error>::ovl'
g++.old-deja/g++.other/overload11.C:87:14: error: no context to resolve type of '&#'translation_unit_decl' not supported by dump_decl#<declaration error>::ovl'
g++.old-deja/g++.other/overload11.C:89:19: error: no context to resolve type of '#'translation_unit_decl' not supported by dump_decl#<declaration error>::ovl'
g++.old-deja/g++.other/overload11.C:90:20: error: no context to resolve type of '&#'translation_unit_decl' not supported by dump_decl#<declaration error>::ovl'
g++.dg/parse/friend5.C:6:19: error: 'void foo()' is already defined in class '#'translation_unit_decl' not supported by dump_type#<type error>'
g++.dg/lookup/java1.C:67:11: error: '#'translation_unit_decl' not supported by dump_decl#<declaration error>::_Jv_Throw' should never be overloaded

The patch below silences this checking DECL_FILE_SCOPE_P in appropriate
places.  I suppose it'd be nice to have testsuite logic to assert that
we never complain about unsupported things in the tree dumpers...

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* decl.c (grokmethod): Check DECL_FILE_SCOPE_P.
	* error.c (dump_decl) [OVERLOAD]: Check DECL_FILE_SCOPE_P.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index b72b588..5735d4e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -13098,7 +13098,7 @@ grokmethod (cp_decl_specifier_seq *declspecs,
 
   if (DECL_IN_AGGR_P (fndecl))
     {
-      if (DECL_CONTEXT (fndecl)
+      if (!DECL_FILE_SCOPE_P (fndecl)
 	  && TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
 	error ("%qD is already defined in class %qT", fndecl,
 	       DECL_CONTEXT (fndecl));
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 4fb47dc..f45f1c2 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1027,12 +1027,13 @@ dump_decl (tree t, int flags)
 	      dump_type (DECL_CONTEXT (t), flags);
 	      pp_cxx_colon_colon (cxx_pp);
 	    }
-	  else if (DECL_CONTEXT (t))
+	  else if (DECL_FILE_SCOPE_P (t))
+	    dump_decl (DECL_NAME (t), flags);
+	  else
 	    {
 	      dump_decl (DECL_CONTEXT (t), flags);
 	      pp_cxx_colon_colon (cxx_pp);
 	    }
-	  dump_decl (DECL_NAME (t), flags);
 	  break;
 	}
 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages
  2010-12-09 15:33 [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages Nathan Froyd
@ 2010-12-09 21:44 ` Jason Merrill
  2010-12-09 22:18   ` Nathan Froyd
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2010-12-09 21:44 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gcc-patches

On 12/09/2010 10:17 AM, Nathan Froyd wrote:
> -      if (DECL_CONTEXT (fndecl)
> +      if (!DECL_FILE_SCOPE_P (fndecl)
>   	&&  TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
>   	error ("%qD is already defined in class %qT", fndecl,
>   	       DECL_CONTEXT (fndecl));

Let's just check DECL_CLASS_SCOPE_P.

> -	  else if (DECL_CONTEXT (t))
> +	  else if (DECL_FILE_SCOPE_P (t))
> +	    dump_decl (DECL_NAME (t), flags);
> +	  else
>   	    {
>   	      dump_decl (DECL_CONTEXT (t), flags);
>   	      pp_cxx_colon_colon (cxx_pp);
>   	    }
> -	  dump_decl (DECL_NAME (t), flags);
>   	  break;

This change breaks printing the name of the decl if it's in a namespace. 
  Just change the if (DECL_CONTEXT to if (!DECL_FILE_SCOPE_P.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages
  2010-12-09 21:44 ` Jason Merrill
@ 2010-12-09 22:18   ` Nathan Froyd
  2010-12-10  9:45     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Froyd @ 2010-12-09 22:18 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

On Thu, Dec 09, 2010 at 04:39:57PM -0500, Jason Merrill wrote:
> On 12/09/2010 10:17 AM, Nathan Froyd wrote:
> >-      if (DECL_CONTEXT (fndecl)
> >+      if (!DECL_FILE_SCOPE_P (fndecl)
> >  	&&  TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
> >  	error ("%qD is already defined in class %qT", fndecl,
> >  	       DECL_CONTEXT (fndecl));
> 
> Let's just check DECL_CLASS_SCOPE_P.

For avoidance of doubt, DECL_CLASS_SCOPE_P is now the complete
condition--the NAMESPACE_DECL check goes away?

> >-	  else if (DECL_CONTEXT (t))
> >+	  else if (DECL_FILE_SCOPE_P (t))
> >+	    dump_decl (DECL_NAME (t), flags);
> >+	  else
> >  	    {
> >  	      dump_decl (DECL_CONTEXT (t), flags);
> >  	      pp_cxx_colon_colon (cxx_pp);
> >  	    }
> >-	  dump_decl (DECL_NAME (t), flags);
> >  	  break;
> 
> This change breaks printing the name of the decl if it's in a
> namespace.  Just change the if (DECL_CONTEXT to if
> (!DECL_FILE_SCOPE_P.

Doh.  Will fix.

-Nathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages
  2010-12-09 22:18   ` Nathan Froyd
@ 2010-12-10  9:45     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2010-12-10  9:45 UTC (permalink / raw)
  To: Nathan Froyd; +Cc: gcc-patches

On 12/09/2010 04:44 PM, Nathan Froyd wrote:
> On Thu, Dec 09, 2010 at 04:39:57PM -0500, Jason Merrill wrote:
>> On 12/09/2010 10:17 AM, Nathan Froyd wrote:
>>> -      if (DECL_CONTEXT (fndecl)
>>> +      if (!DECL_FILE_SCOPE_P (fndecl)
>>>   	&&   TREE_CODE (DECL_CONTEXT (fndecl)) != NAMESPACE_DECL)
>>>   	error ("%qD is already defined in class %qT", fndecl,
>>>   	       DECL_CONTEXT (fndecl));
>>
>> Let's just check DECL_CLASS_SCOPE_P.
>
> For avoidance of doubt, DECL_CLASS_SCOPE_P is now the complete
> condition--the NAMESPACE_DECL check goes away?

Yes.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-10  7:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-09 15:33 [PATCH,c++] fix bogus complaints about translation_unit_decl in error messages Nathan Froyd
2010-12-09 21:44 ` Jason Merrill
2010-12-09 22:18   ` Nathan Froyd
2010-12-10  9:45     ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).