Commit 916c5919 by Joseph Myers Committed by Joseph Myers

re PR c/11250 (-pedantic accepts `char a[] = ("x");')

	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.

From-SVN: r85022
parent bf6c40e9
2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk>
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.
2004-07-21 David S. Miller <davem@nuts.davemloft.net>
* config/sparc/sparc.c (sparc_rtx_costs): Fix typo in previous
......
......@@ -204,7 +204,8 @@ do { \
%type <ttype> offsetof_member_designator
%type <ttype> scspec SCSPEC STATIC TYPESPEC TYPE_QUAL maybe_volatile
%type <ttype> initdecls notype_initdecls initdcl notype_initdcl init
%type <ttype> initdecls notype_initdecls initdcl notype_initdcl
%type <exprtype> init
%type <ttype> simple_asm_expr maybeasm asm_stmt asm_argument
%type <ttype> asm_operands nonnull_asm_operands asm_operand asm_clobbers
%type <ttype> maybe_attribute attributes attribute attribute_list attrib
......@@ -631,7 +632,7 @@ primary:
| CONSTANT
{ $$.value = $1; $$.original_code = ERROR_MARK; }
| STRING
{ $$.value = $1; $$.original_code = ERROR_MARK; }
{ $$.value = $1; $$.original_code = STRING_CST; }
| FUNC_NAME
{ $$.value = fname_decl (C_RID_CODE ($1), $1);
$$.original_code = ERROR_MARK; }
......@@ -640,9 +641,11 @@ primary:
$2 = groktypename ($2);
really_start_incremental_init ($2); }
initlist_maybe_comma '}' %prec UNARY
{ tree constructor = pop_init_level (0);
{ struct c_expr init = pop_init_level (0);
tree constructor = init.value;
tree type = $2;
finish_init ();
maybe_warn_string_init (type, init);
if (pedantic && ! flag_isoc99)
pedwarn ("ISO C90 forbids compound literals");
......@@ -1391,7 +1394,8 @@ initdcl:
init
/* Note how the declaration of the variable is in effect while its init is parsed! */
{ finish_init ();
finish_decl ($<ttype>5, $6, $2); }
maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
finish_decl ($<ttype>5, $6.value, $2); }
| declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0,
chainon ($3, all_prefix_attributes));
......@@ -1407,7 +1411,8 @@ notype_initdcl:
init
/* Note how the declaration of the variable is in effect while its init is parsed! */
{ finish_init ();
finish_decl ($<ttype>5, $6, $2); }
maybe_warn_string_init (TREE_TYPE ($<ttype>5), $6);
finish_decl ($<ttype>5, $6.value, $2); }
| notype_declarator maybeasm maybe_attribute
{ tree d = start_decl ($1, current_declspecs, 0,
chainon ($3, all_prefix_attributes));
......@@ -1476,13 +1481,13 @@ scspec:
init:
expr_no_commas
{ $$ = $1.value; }
{ $$ = $1; }
| '{'
{ really_start_incremental_init (NULL_TREE); }
initlist_maybe_comma '}'
{ $$ = pop_init_level (0); }
| error
{ $$ = error_mark_node; }
{ $$.value = error_mark_node; $$.original_code = ERROR_MARK; }
;
/* `initlist_maybe_comma' is the guts of an initializer in braces. */
......@@ -1522,7 +1527,7 @@ initval:
initlist_maybe_comma '}'
{ process_init_element (pop_init_level (0)); }
| expr_no_commas
{ process_init_element ($1.value); }
{ process_init_element ($1); }
| error
;
......
......@@ -119,8 +119,9 @@ struct c_expr
/* The value of the expression. */
tree value;
/* Record the original binary operator of an expression, which may
have been changed by fold, or ERROR_MARK for other expressions
(including parenthesized expressions). */
have been changed by fold, STRING_CST for unparenthesised string
constants, or ERROR_MARK for other expressions (including
parenthesized expressions). */
enum tree_code original_code;
};
......@@ -244,14 +245,15 @@ extern tree build_modify_expr (tree, enum tree_code, tree);
extern void store_init_value (tree, tree);
extern void error_init (const char *);
extern void pedwarn_init (const char *);
extern void maybe_warn_string_init (tree, struct c_expr);
extern void start_init (tree, tree, int);
extern void finish_init (void);
extern void really_start_incremental_init (tree);
extern void push_init_level (int);
extern tree pop_init_level (int);
extern struct c_expr pop_init_level (int);
extern void set_init_index (tree, tree);
extern void set_init_label (tree);
extern void process_init_element (tree);
extern void process_init_element (struct c_expr);
extern tree build_compound_literal (tree, tree);
extern void pedwarn_c90 (const char *, ...) ATTRIBUTE_PRINTF_1;
extern void pedwarn_c99 (const char *, ...) ATTRIBUTE_PRINTF_1;
......
2004-07-22 Joseph S. Myers <jsm@polyomino.org.uk>
PR c/11250
* gcc.dg/init-string-1.c: New test.
2004-07-21 Jakub Jelinek <jakub@redhat.com>
PR middle-end/15345
......
/* String initializers for arrays must not be parenthesized. Bug
11250 from h.b.furuseth at usit.uio.no. */
/* Origin: Joseph Myers <jsm@polyomino.org.uk> */
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic-errors" } */
#include <stddef.h>
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 } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment