Article View: gnu.g++.bug
Article #1106Patch for placement syntax new op bug in g++ 2.3.1
From: Gnanasekaran Swaminathan
Date: Fri, 06 Nov 1992 15:40
Date: Fri, 06 Nov 1992 15:40
185 lines
7278 bytes
7278 bytes
Following program results in parse errors when compiled with
g++ 2.3.1 on Sun3 running SunOS 4.1.2
#include <iostream.h>
#include <stddef.h>
void* operator new (size_t n, void* p) {
cout << "::new(size_t " << n << ", " << p << ")\n";
return p;
}
class A {
int i;
public:
A(int j): i(j) { cout << "A::A(int)\n"; }
void* operator new (size_t n) {
cout << "new(size_t " << n << ")\n";
return ::new char[n];
}
void* operator new (size_t n, void* p) {
cout << "new(size_t " << n << ", " << p << ")\n";
return p;
}
};
int main(int ac, char** av)
{
A* a = new A(10);
a = new (a) A(20);
char** t = new (char*)[10];
t = new (a) (char*)[10];
t = new (a) (char*);
t = new (char*);
t = new (a) char*[10];
t = new char*[10];
t = new (a) char*;
t = new char*;
t = new const char*;
t = new (const char*);
t = new (const char*)[10];
t = new (a) const char*;
t = new (a) (const char*);
t = new (a) (const char*)[10];
}
cd /ug0/users/gs4t/g++/g++-tests/
c++ -v tnew.cc
Reading specs from /home/gs4t/bin/lib/gcc-lib/sun3os4/2.3.1/specs
gcc version 2.3.1
/home/gs4t/bin/lib/gcc-lib/sun3os4/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__mc68000 -D__sun -D__unix -D__HAVE_68881__ -D__mc68020__ -Dmc68020 tnew.cc /usr/tmp/cca08862.i
GNU CPP version 2.3.1 (68k, MIT syntax)
/home/gs4t/bin/lib/gcc-lib/sun3os4/2.3.1/cc1plus /usr/tmp/cca08862.i -quiet -dumpbase tnew.cc -version -o /usr/tmp/cca08862.s
GNU C++ version 2.3.1 (68k, MIT syntax) compiled by GNU C version 2.1.
tnew.cc: In function `int main (int, char **)':
tnew.cc:27: parse error before `)'
tnew.cc:29: warning: ANSI C++ forbids array dimensions with parenthesized type
tnew.cc:30: parse error before `('
tnew.cc:31: parse error before `('
tnew.cc:39: warning: ANSI C++ forbids array dimensions with parenthesized type
tnew.cc:41: parse error before `('
tnew.cc:42: parse error before `('
Compilation exited abnormally with code 1 at Fri Nov 6 18:36:57
Here is a patch to fix the above bug.
*** cp-parse.y Fri Nov 6 16:20:53 1992
--- cp-parse.y~ Fri Nov 6 20:22:23 1992
***************
*** 1068,1089 ****
{ $$ = c_alignof (groktypename ($3)); }
| .scope new typename %prec '='
{ $$ = build_new ($2, $3, NULL_TREE, $$); }
- | .scope new '(' nonnull_exprlist ')' typename %prec '='
- { $$ = build_new ($4, $6, NULL_TREE, $$); }
| .scope new typespec '(' nonnull_exprlist ')'
{ $$ = build_new ($2, $3, $5, $$); }
- | .scope NEW '(' nonnull_exprlist ')' typespec '(' nonnull_exprlist ')'
- { $$ = build_new ($4, $6, $8, $$); }
| .scope new typespec LEFT_RIGHT
{ $$ = build_new ($2, $3, NULL_TREE, $$); }
- | .scope NEW '(' nonnull_exprlist ')' typespec LEFT_RIGHT
- { $$ = build_new ($4, $6, NULL_TREE, $$); }
| .scope new typename '=' init %prec '='
{ $$ = build_new ($2, $3, $5, $$); }
- | .scope NEW '(' nonnull_exprlist ')' typename '=' init %prec '='
- { $$ = build_new ($4, $6, $8, $$); }
/* I am not going to add placement syntax to the below complex rules
because Ken says the syntax is illegal. (mrs) */
/* I'm not sure why this is disallowed. But since it is, and it
--- 1068,1081 ----
***************
*** 1098,1121 ****
typename = build_decl_list ($4, absdcl);
pedwarn ("ANSI C++ forbids array dimensions with parenthesized type");
$$ = build_new ($2, typename, NULL_TREE, $$);
}
| .scope new '(' nonempty_type_quals absdcl ')' '[' nonmomentary_expr ']'
{ goto illegal_new_array; }
!
| .scope new '(' typed_typespecs absdcl ')'
{ $$ = build_new ($2, build_decl_list ($4, $5), NULL_TREE, $$); }
! | .scope NEW '(' nonnull_exprlist ')' '(' typed_typespecs absdcl ')'
! { $$ = build_new ($4, build_decl_list ($7, $8), NULL_TREE, $$); }
| .scope new '(' nonempty_type_quals absdcl ')'
{ $$ = build_new ($2, build_decl_list ($4, $5), NULL_TREE, $$); }
! | .scope NEW '(' nonnull_exprlist ')' '(' nonempty_type_quals absdcl ')'
! { $$ = build_new ($4, build_decl_list ($7, $8), NULL_TREE, $$); }
/* Unswallow a ':' which is probably meant for ?: expression. */
| .scope new TYPENAME_COLON
{ yyungetc (':', 1); $$ = build_new ($2, $3, NULL_TREE, $$); }
- | .scope NEW '(' nonnull_exprlist ')' TYPENAME_COLON
- { yyungetc (':', 1); $$ = build_new ($4, $6, NULL_TREE, $$); }
| delete cast_expr %prec UNARY
{ tree expr = stabilize_reference (convert_from_reference ($2));
tree type = TREE_TYPE (expr);
--- 1090,1114 ----
typename = build_decl_list ($4, absdcl);
pedwarn ("ANSI C++ forbids array dimensions with parenthesized type");
$$ = build_new ($2, typename, NULL_TREE, $$);
}
+ | .scope NEW '(' typed_typespecs absdcl ')' '[' nonmomentary_expr ']'
+ { $<ttype>2 = NULL_TREE; goto illegal_new_array; }
| .scope new '(' nonempty_type_quals absdcl ')' '[' nonmomentary_expr ']'
{ goto illegal_new_array; }
! | .scope NEW '(' nonempty_type_quals absdcl ')' '[' nonmomentary_expr ']'
! { $<ttype>2 = NULL_TREE; goto illegal_new_array; }
| .scope new '(' typed_typespecs absdcl ')'
{ $$ = build_new ($2, build_decl_list ($4, $5), NULL_TREE, $$); }
! | .scope NEW '(' typed_typespecs absdcl ')'
! { $$ = build_new (NULL_TREE, build_decl_list ($4, $5), NULL_TREE, $$); }
| .scope new '(' nonempty_type_quals absdcl ')'
{ $$ = build_new ($2, build_decl_list ($4, $5), NULL_TREE, $$); }
! | .scope NEW '(' nonempty_type_quals absdcl ')'
! { $$ = build_new (NULL_TREE, build_decl_list ($4, $5), NULL_TREE, $$); }
/* Unswallow a ':' which is probably meant for ?: expression. */
| .scope new TYPENAME_COLON
{ yyungetc (':', 1); $$ = build_new ($2, $3, NULL_TREE, $$); }
| delete cast_expr %prec UNARY
{ tree expr = stabilize_reference (convert_from_reference ($2));
tree type = TREE_TYPE (expr);
***************
*** 1605,1619 ****
}
;
*/
! new: NEW
{ $$ = NULL_TREE; }
| NEW '{' nonnull_exprlist '}'
{
$$ = $3;
pedwarn ("old style placement syntax, use () instead");
}
| NEW DYNAMIC %prec EMPTY
{ $$ = void_type_node; }
| NEW DYNAMIC '(' string ')'
{ $$ = combine_strings ($4); }
--- 1598,1614 ----
}
;
*/
! new: NEW %prec EMPTY
{ $$ = NULL_TREE; }
| NEW '{' nonnull_exprlist '}'
{
$$ = $3;
pedwarn ("old style placement syntax, use () instead");
}
+ | NEW '(' nonnull_exprlist ')'
+ { $$ = $3; }
| NEW DYNAMIC %prec EMPTY
{ $$ = void_type_node; }
| NEW DYNAMIC '(' string ')'
{ $$ = combine_strings ($4); }
Technical Details
Message-ID:
<9211070140.AA41432@kelvin.seas.Virginia.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!kelvin.seas.virginia.edu!gs4tShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!kelvin.seas.virginia.edu!gs4t From: gs4t@kelvin.seas.virginia.edu (Gnanasekaran Swaminathan) Subject: Patch for placement syntax new op bug in g++ 2.3.1 Message-ID: <9211070140.AA41432@kelvin.seas.Virginia.EDU> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 6 Nov 1992 15:40:29 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 186