public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/3304: g++ accepts array definition with non-constant dimensions
@ 2001-06-20 13:16 jeggers
  0 siblings, 0 replies; 2+ messages in thread
From: jeggers @ 2001-06-20 13:16 UTC (permalink / raw)
  To: gcc-gnats; +Cc: gsheppar

>Number:         3304
>Category:       c++
>Synopsis:       g++ accepts array definition with non-constant dimensions
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 20 13:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     John Eggers
>Release:        GCC 2.96 20000731
>Organization:
>Environment:
Linux 7.0
>Description:
g++ accepts the following as correct, even with the -ansi
switch.

//***** Begin Code Fragment *****
   cout << "Enter the sum (a positive integer): ";
   cin >> sum;
   
   cout << "Enter the size (a positive integer): ";
   cin >> size;
   
   cout << endl;
   
   const int SIZE = size;
   const int SUM = sum;
   
   int Sum[SIZE+1][SUM+1];
//***** End Code Fragment *****

Note:  g++ also accepts

   int (*Sum)[SUM+1] = new int[SIZE+1][SUM+1];
>How-To-Repeat:
Compile attached file with g++.  Also, comment-out the line
   int Sum[SIZE+1][SUM+1];
and un-comment the line
   int (*Sum)[SUM+1] = new int[SIZE+1][SUM+1];
and then compile.
>Fix:
I do not have the expertise to suggest a fix, except to note
that the above code should be rejected by any ANSI-compliant
C++ compiler (although, I found it very convenient that g++
let me get away with the above code).
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test1.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test1.cpp"

I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlOjpz
dGQ7CgppbnQgbWFpbigpIHsKCiAgIHZlY3RvcjxpbnQ+IHNldCgwKTsKICAgCiAgIGludCBzdW0g
PSAwOwogICBpbn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swXSA9IDE7CiAg
IH0KICAgCiAgIGZvciAoaiA9IDE7IGogPD0gU1VNOyArK2opIHsKICAgICAgU3VtWzBdW2pdID0g
MDsKICAgfQogICAKICAgZm9yIChpID0gMTsgaSA8PSBTSVpFOyArK2kpIHsKICAgICAgZm9yIChq
ID0gMTsgaiA8PSBTVU07ICsraikgewogICAgICAgICBTdW1baV1bal0gPSBTdW1baS0xXVtqXTsK
ICAgICAgfQogICB9CiAgIAogICBjb3V0IDw8ICJTdWNjZXNzZnVsbHkgaW5pdGlhbGl6ZWQgYXJy
YXkuIiA8PCBlbmRsOwogICAKICAgcmV0dXJuIDA7Cn0K


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: c++/3304: g++ accepts array definition with non-constant dimensions
@ 2001-08-11 14:39 gdr
  0 siblings, 0 replies; 2+ messages in thread
From: gdr @ 2001-08-11 14:39 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, gdr, gsheppar, jeggers, nobody

Synopsis: g++ accepts array definition with non-constant dimensions

Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-By: gdr
Responsible-Changed-When: Sat Aug 11 14:39:53 2001
Responsible-Changed-Why:
    Analyzed.
State-Changed-From-To: open->closed
State-Changed-By: gdr
State-Changed-When: Sat Aug 11 14:39:53 2001
State-Changed-Why:
    This is not a bug.  GCC emits a warning with -pedantic.
    
    -- Gaby

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3304&database=gcc


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-08-11 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-20 13:16 c++/3304: g++ accepts array definition with non-constant dimensions jeggers
2001-08-11 14:39 gdr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).