[c-family] Plug small loophole in the C/C++ binding for Ada

Message ID 3509368.rCfb0ir6Hm@polaris
State New
Headers show
Series
  • [c-family] Plug small loophole in the C/C++ binding for Ada
Related show

Commit Message

Eric Botcazou June 1, 2018, 8:37 a.m.
This plugs a small loophole in the improved handling of forward declarations 
in the C/C++ binding for Ada, whereby a forward declaration for a type is not 
generated if the typedef declaration making it necessary uses the same name as 
the tag of the type.

Tested on x86-64/Linux, applied on the mainline and 8 branch.


2018-06-01  Eric Botcazou  <ebotcazou@adacore.com>

c-family/
	* c-ada-spec.c (dump_ada_declaration) <TYPE_DECL>: Generate a forward
	declaration for a typedef independently of whether the declaration of
	the subtype is generated.

-- 
Eric Botcazou

Patch

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 260913)
+++ c-ada-spec.c	(working copy)
@@ -2734,19 +2734,25 @@  dump_ada_declaration (pretty_printer *bu
 
 	  if (TYPE_NAME (typ))
 	    {
-	      /* If types have same representation, and same name (ignoring
-		 casing), then ignore the second type.  */
+	      /* If the types have the same name (ignoring casing), then ignore
+		 the second type, but forward declare the first if need be.  */
 	      if (type_name (typ) == type_name (TREE_TYPE (t))
 		  || !strcasecmp (type_name (typ), type_name (TREE_TYPE (t))))
 		{
+		  if (RECORD_OR_UNION_TYPE_P (typ) && !TREE_VISITED (stub))
+		    {
+		      INDENT (spc);
+		      dump_forward_type (buffer, typ, t, 0);
+		    }
+
 		  TREE_VISITED (t) = 1;
 		  return 0;
 		}
 
 	      INDENT (spc);
 
-	      if (RECORD_OR_UNION_TYPE_P (typ))
-		dump_forward_type (buffer, stub, t, spc);
+	      if (RECORD_OR_UNION_TYPE_P (typ) && !TREE_VISITED (stub))
+		dump_forward_type (buffer, typ, t, spc);
 
 	      pp_string (buffer, "subtype ");
 	      dump_ada_node (buffer, t, type, spc, false, true);