[RFC v1 1/5] gcc/c/c-decl.cc: Return arrays

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Alejandro Colomar <alx@xxxxxxxxxx>
---
 gcc/c/c-decl.cc | 46 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 7 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index ad66d7d258b..15dcf61dec1 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -3982,6 +3982,7 @@ undeclared_variable (location_t loc, tree id)
 		    id, suggestion);
 	}
       else
+// XXX:  'int f(int n)[n];'  triggers this
 	error_at (loc, "%qE undeclared here (not in a function)", id);
       scope = current_scope;
     }
@@ -7386,6 +7387,7 @@ grokdeclarator (const struct c_declarator *declarator,
 		else if ((decl_context == NORMAL || decl_context == FIELD)
 			 && current_scope == file_scope)
 		  {
+// XXX:  'int f(void)[m];'  triggers this
 		    error_at (loc, "variably modified %qE at file scope", name);
 		    size = integer_one_node;
 		  }
@@ -7611,13 +7613,41 @@ grokdeclarator (const struct c_declarator *declarator,
 	      }
 	    if (TREE_CODE (type) == ARRAY_TYPE)
 	      {
-		if (name)
-		  error_at (loc, "%qE declared as function returning an array",
-		      	    name);
-		else
-		  error_at (loc, "type name declared as function returning "
-		      	    "an array");
-		type = integer_type_node;
+// TODO
+	        /* Transfer const-ness of array into that of type pointed to.  */
+	        type = TREE_TYPE (type);
+	        if (orig_qual_type != NULL_TREE)
+	          {
+		    if (orig_qual_indirect == 0)
+		      orig_qual_type = TREE_TYPE (orig_qual_type);
+		    else
+		      orig_qual_indirect--;
+		  }
+		if (type_quals)
+		  type = c_build_qualified_type (type, type_quals, orig_qual_type,
+						 orig_qual_indirect);
+
+		/* The pointed-to type may need a decl expr (see above).  */
+		if (!TYPE_NAME (type) && c_type_variably_modified_p (type))
+		  {
+		    bool bind_p = decl_context == TYPENAME
+				  || decl_context == FIELD
+				  || decl_context == PARM;
+		    add_decl_expr (loc, type, bind_p ? expr : NULL, true);
+		  }
+
+		type = c_build_pointer_type (type);
+		type_quals = array_ptr_quals;
+		if (type_quals)
+		  type = c_build_qualified_type (type, type_quals);
+
+		/* We don't yet implement attributes in this context.  */
+		if (array_ptr_attrs != NULL_TREE)
+		  warning_at (loc, OPT_Wattributes,
+			      "attributes in return array declarator ignored");
+
+		size_varies = false;
+// TODO
 	      }
 
 	    /* Construct the function type and go to the next
@@ -7978,6 +8008,7 @@ grokdeclarator (const struct c_declarator *declarator,
 
 	if (TREE_CODE (type) == ARRAY_TYPE)
 	  {
+// XXX:  Copy BEGIN
 	    /* Transfer const-ness of array into that of type pointed to.  */
 	    type = TREE_TYPE (type);
 	    if (orig_qual_type != NULL_TREE)
@@ -8012,6 +8043,7 @@ grokdeclarator (const struct c_declarator *declarator,
 
 	    size_varies = false;
 	    array_parameter_p = true;
+// XXX:  Copy END
 	  }
 	else if (TREE_CODE (type) == FUNCTION_TYPE)
 	  {
-- 
2.49.0




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux