Bug 7948 - gcc fails to fault gnu extension with -std=c99
Summary: gcc fails to fault gnu extension with -std=c99
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3
: P3 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, diagnostic
: 29125 (view as bug list)
Depends on:
Blocks: 16989
  Show dependency treegraph
 
Reported: 2002-09-17 06:56 UTC by Richard Earnshaw
Modified: 2006-09-19 03:30 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-12-10 05:45:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Earnshaw 2002-09-17 06:56:01 UTC
	ISO C99 states that a variable length array may only be used with
	"ordinary identifiers" (ie not structure members).  That makes the
	following code invalid:

	void f(int len)
	{
	  struct {
	    char x[len];
	  } a;
	  /* ... */
	}

	However, gcc accepts this without complaint if the -std=c99 flag is
	used (even if -pedantic is given).

Release:
3.3 20020917 (experimental)

Environment:
System: Linux pc960.cambridge.arm.com 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: arm-unknown-elf
configured with: /home/rearnsha/gnusrc/egcs-cross/configure --prefix=/work/rearnsha/gnu/install --disable-checking --target=arm-elf --with-headers=/home/rearnsha/gnusrc/egcs-cross/newlib/libc/include

How-To-Repeat:
	compile the above code fragment with

		gcc -c -std=c99 -pedantic 

	Note that the fragment _is_ correctly rejected if -std=c89 is used.
Comment 1 Joseph S. Myers 2002-09-17 08:27:48 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.  More people were complaining about getting
    warnings with -std=c99 -pedantic for the cases C99 permits
    than are now complaining about not getting warnings for
    cases it doesn't permit.  VLAs are documented as broken
    (meaning not closely following C99) in c99status.html.
Comment 2 Andrew Pinski 2005-12-10 05:45:16 UTC
_Complex int is another extension which is only warned with -pedantic included with -std=c99.
Comment 3 Mike Stump 2006-05-09 00:48:58 UTC
I have a fix for this.
Comment 4 mrs@gcc.gnu.org 2006-05-18 18:22:23 UTC
Subject: Bug 7948

Author: mrs
Date: Thu May 18 18:22:12 2006
New Revision: 113888

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=113888
Log:
	Fix up vla, vm and [*] sematics.

	PR c/18740
	PR c/7948
	PR c/25802
	* c-tree.h (struct c_arg_info): Add had_vla_unspec.
	(c_vla_unspec_p): Add.
	(c_vla_type_p): Add.
	* c-decl.c (struct c_scope): Add had_vla_unspec.
	(build_array_declarator): Add support for [*].
	(grokdeclarator): Likewise.
	(grokparms): Likewise.
	(get_parm_info): Likewise.
	* c-objc-common.c (c_vla_unspec_p): Likewise.
	* c-objc-common.h (LANG_HOOKS_TREE_INLINING_VAR_MOD_TYPE_P): Likewise.
	* c-parser.c (c_parser_typeof_specifier): Evaluate arguments to
	typeof when argument is a variably modified type not inside sizeof or alignof.
	(c_parser_direct_declarator_inner): Propagate errors.
	(c_parser_sizeof_expression): Add support for [*].
	* c-typeck.c (c_vla_type_p): Add.
	(composite_type): Add support for vla compositing.
	(comptypes_internal): Add support for vla compatibility.
	(c_expr_sizeof_expr): Evaluate vla arguments.
	* tree.c (variably_modified_type_p): Update comment for [*].

testsuite:
	* gcc.dg/c90-arraydecl-1.c: Update for vla, vm [*] fixups.
	* gcc.dg/vla-4.c: Add.
	* gcc.dg/vla-5.c: Add.
	* gcc.dg/vla-6.c: Add.

Added:
    trunk/gcc/testsuite/gcc.dg/vla-4.c
    trunk/gcc/testsuite/gcc.dg/vla-5.c
    trunk/gcc/testsuite/gcc.dg/vla-6.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-decl.c
    trunk/gcc/c-objc-common.c
    trunk/gcc/c-objc-common.h
    trunk/gcc/c-parser.c
    trunk/gcc/c-tree.h
    trunk/gcc/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/c90-arraydecl-1.c
    trunk/gcc/tree.c

Comment 5 Joseph S. Myers 2006-06-04 17:00:06 UTC
Fixed for 4.2.
Comment 6 Andrew Pinski 2006-09-19 03:30:54 UTC
*** Bug 29125 has been marked as a duplicate of this bug. ***