RFA: Disallow c99 flexible array support in C++

Nick Clifton nickc@redhat.com
Mon Dec 29 13:30:00 GMT 2003


Hi Guys,

  The patch below disables support for c99 flexible array types when
  compiling C++ programs.  The ISO/IEC 14882-1998 spec in section 9.2
  8 says:

    When an array is used as the type of a nonstatic member
    all dimensions shall be specified.

  The following C++ test program ought to generate an error:

    typedef int A[];
    struct S { A a; };

  But currently it does not.  With this patch applied it generates:

    error: field `a' has incomplete type

  May I apply this patch please ?

Cheers
        Nick

gcc/cp/ChangeLog
2003-12-29  Nick Clifton  <nickc@redhat.com>

	* decl.c (grokdeclarator): Suppress support for C99 flexible
	arrays.

Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1169
diff -c -3 -p -r1.1169 decl.c
*** gcc/cp/decl.c	29 Dec 2003 02:42:16 -0000	1.1169
--- gcc/cp/decl.c	29 Dec 2003 11:22:28 -0000
*************** grokdeclarator (tree declarator,
*** 8027,8040 ****
        }
      else if (decl_context == FIELD)
        {
! 	/* The C99 flexible array extension.  */
  	if (!staticp && TREE_CODE (type) == ARRAY_TYPE
  	    && TYPE_DOMAIN (type) == NULL_TREE)
  	  {
  	    tree itype = compute_array_index_type (dname, integer_zero_node);
  	    type = build_cplus_array_type (TREE_TYPE (type), itype);
  	  }
! 
  	if (type == error_mark_node)
  	  {
  	    /* Happens when declaring arrays of sizes which
--- 8027,8042 ----
        }
      else if (decl_context == FIELD)
        {
! #if 0 /* Do not support the C99 flexible array extension.  The ISO/IEC
! 	 14882-1998 spec in section 9.2 8 says:	 When an array is used as
! 	 the type of a non-static member all dimensions shall be specified.  */
  	if (!staticp && TREE_CODE (type) == ARRAY_TYPE
  	    && TYPE_DOMAIN (type) == NULL_TREE)
  	  {
  	    tree itype = compute_array_index_type (dname, integer_zero_node);
  	    type = build_cplus_array_type (TREE_TYPE (type), itype);
  	  }
! #endif
  	if (type == error_mark_node)
  	  {
  	    /* Happens when declaring arrays of sizes which
                



More information about the Gcc-patches mailing list