Allow more forms of address expressions in static initializers.
There were several forms that should be permitted but were not, such as &"str"[1], &*"str", &*a (where a is an array), and &*f (where f is a function). This fixes #15 and also certain other cases illustrated in the following example: char a[10]; int main(void); static char *s1 = &"string"[1]; static char *s2 = &*"string"; static char *s3 = &*a; static int (*f2)(void)=&*main;
This commit is contained in:
parent
e8d90a1b69
commit
e36503508a
24
Parser.pas
24
Parser.pas
|
@ -1966,14 +1966,19 @@ var
|
|||
errorFound := true;
|
||||
end; {else}
|
||||
tp := Subscript(tree^.left);
|
||||
if tp^.kind <> arrayType then
|
||||
Error(47)
|
||||
else begin
|
||||
tp := tp^.atype;
|
||||
offset := offset + size*tp^.size;
|
||||
Subscript := tp;
|
||||
end; {else}
|
||||
end {if}
|
||||
else begin
|
||||
size := 0;
|
||||
tp := Subscript(tree);
|
||||
end; {else}
|
||||
if tp^.kind = arrayType then begin
|
||||
tp := tp^.atype;
|
||||
offset := offset + size*tp^.size;
|
||||
Subscript := tp;
|
||||
end {if}
|
||||
else if tp^.kind = functionType then begin
|
||||
Subscript := tp;
|
||||
end {else if}
|
||||
else begin
|
||||
Error(47);
|
||||
errorFound := true;
|
||||
|
@ -2010,6 +2015,11 @@ var
|
|||
iPtr^.pName := ip^.name;
|
||||
end; {else}
|
||||
end {else if}
|
||||
else if tree^.token.kind = stringConst then begin
|
||||
Subscript := StringType(tree^.token.prefix);
|
||||
iPtr^.isName := false;
|
||||
iPtr^.pStr := tree^.token.sval;
|
||||
end {else if}
|
||||
else begin
|
||||
Error(47);
|
||||
errorFound := true;
|
||||
|
|
4
cc.notes
4
cc.notes
|
@ -1707,6 +1707,10 @@ int foo(int[42]);
|
|||
|
||||
(Michael Hackett)
|
||||
|
||||
176. Certain address expressions (e.g. &"string"[1]) would cause spurious errors if they were used in the initializers of global or static variables.
|
||||
|
||||
(Devin Reade)
|
||||
|
||||
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
|
||||
|
||||
1. In some situations, fread() reread the first 1K or so of the file.
|
||||
|
|
Loading…
Reference in New Issue