From 3ad5f027d89dd828eff822371e1791f520d83c41 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Wed, 21 Jul 2004 23:46:20 +0000 Subject: PR c/11250 * c-parse.in (init): Change to exprtype. (primary): Set original_code for STRING to STRING_CST. Call maybe_warn_string_init for compound literals. (initdcl, notype_initdcl): Call maybe_warn_string_init. (initval): Update. * c-tree.h (maybe_warn_string_init): New. (pop_init_level, process_init_element): Use struct c_expr. (struct c_expr): Update comment. * c-typeck.c (maybe_warn_string_init): New function. (digest_init): Call it. Additional parameter strict_string. All callers changed. (output_init_element): Likewise. (struct constructor_stack): Use struct c_expr for replacement_value. (really_start_incremental_init, push_init_level): Update. (pop_init_level): Update. Return struct c_expr. (process_init_level): Update. Take struct c_expr argument. testsuite: * gcc.dg/init-string-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@85022 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/testsuite/gcc.dg/init-string-1.c | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/init-string-1.c (limited to 'gcc/testsuite/gcc.dg/init-string-1.c') diff --git a/gcc/testsuite/gcc.dg/init-string-1.c b/gcc/testsuite/gcc.dg/init-string-1.c new file mode 100644 index 00000000000..ace3b34562e --- /dev/null +++ b/gcc/testsuite/gcc.dg/init-string-1.c @@ -0,0 +1,59 @@ +/* String initializers for arrays must not be parenthesized. Bug + 11250 from h.b.furuseth at usit.uio.no. */ +/* Origin: Joseph Myers */ +/* { dg-do compile } */ +/* { dg-options "-std=c99 -pedantic-errors" } */ + +#include + +char *a = "a"; +char *b = ("b"); +char *c = (("c")); + +char d[] = "d"; +char e[] = ("e"); /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 14 } */ +char f[] = (("f")); /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 16 } */ + +signed char g[] = { "d" }; +unsigned char h[] = { ("e") }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 20 } */ +signed char i[] = { (("f")) }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 22 } */ + + +struct s { char a[10]; int b; wchar_t c[10]; }; + +struct s j = { + "j", + 1, + (L"j") +}; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 32 } */ +struct s k = { + (("k")), /* { dg-bogus "warning" "warning in place of error" } */ + /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 35 } */ + 1, + L"k" +}; + +struct s l = { + .c = (L"l"), /* { dg-bogus "warning" "warning in place of error" } */ + /* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 42 } */ + .a = "l" +}; + +struct s m = { + .c = L"m", + .a = ("m") +}; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 50 } */ + +char *n = (char []){ "n" }; + +char *o = (char []){ ("o") }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 55 } */ + +wchar_t *p = (wchar_t [5]){ (L"p") }; /* { dg-bogus "warning" "warning in place of error" } */ +/* { dg-error "parenthesized|near init" "paren array" { target *-*-* } 58 } */ -- cgit v1.2.3