This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: Disallow c99 flexible array support in C++


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
                


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]