c++/8237: parse error for legal code - works on intel and solaris compilers

joel.zuhars@med.ge.com joel.zuhars@med.ge.com
Tue Oct 15 15:56:00 GMT 2002


>Number:         8237
>Category:       c++
>Synopsis:       parse error for legal code - works on intel and solaris compilers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 15 15:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Joel Zuhars
>Release:        gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
>Organization:
>Environment:
Linux on intel machine
>Description:
Hello, the following simple code gives a parse error when compiling with g++, but works on both intel and solaris compilers. Is it a bug, or am I just missing something obvious? Thanks for any help.

> cat testVec.C
#include <stdio.h>

class A {
public:
  A() { printf("Acon\n"); }
  };

class B {
public:
  B(A a) { printf("BAcon\n"); }
  void form() { printf("Bform\n"); }
  };

int main() {
  B(A()).form();
}

brutus [joel]: /home/joel/tvec[21]
> g++ testVec.C -o TestVec
testVec.C: In function `int main ()':
testVec.C:16: parse error before `.'

brutus [joel]: /home/joel/tvec [22]         
> icc testVec.C -o TestVec

testVec.C

brutus [joel]: /home/joel/tvec [23]
> TestVec 
Acon
BAcon
Bform
     
brutus [joel]: /home/joel/tvec [24]
> g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)

>How-To-Repeat:

>Fix:
use "A a; B(a).form();" instead of "B(A()).form();"
or add constructor A(int i) and use "B(A(1)).form();"
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list