diff mbox

[c++] fix bogus complaints about translation_unit_decl in error messages

Message ID 20101209151743.GH25904@nightcrawler
State New
Headers show

Commit Message

Nathan Froyd Dec. 9, 2010, 3:17 p.m. UTC
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.

Comments

Jason Merrill Dec. 9, 2010, 9:39 p.m. UTC | #1
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
Nathan Froyd Dec. 9, 2010, 9:44 p.m. UTC | #2
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
Jason Merrill Dec. 10, 2010, 7:02 a.m. UTC | #3
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
diff mbox

Patch

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;
 	}