Bug 102399 - compiler error with construction of temporary objects
compiler error with construction of temporary objects
Product: Red Hat Enterprise Linux 2.1
Classification: Red Hat
Component: gcc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2003-08-14 14:52 EDT by Tom Honermann
Modified: 2007-11-30 17:06 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-07 10:36:21 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Tom Honermann 2003-08-14 14:52:37 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624

Description of problem:
Compiler is failing to compile the following code:

    typedef     int             PAMSInt;
    typedef     unsigned short* PAMSStr;

    unsigned short PS_T[] = { 0x0062, 0x0061, 0x006e, 0x0064, 0x0073,  0 } ;

    template <class A, class B>
    class PAMSClass {
                    PAMSClass(A a, B b) {
                            a1 = a;
                            b1 = b;
                    A a1;
                    B b1;
    /* This line will cause the compiler to fail with an error stating:
     *     test.cpp:24: parse error before `1'
      PAMSClass<PAMSStr, PAMSInt> pamsclass(PAMSStr(PS_T),PAMSInt(1));
    /* This line will compile normally.  The difference between this and
     *   the previous line is that a cast is used instead of constructing
     *   a temporary of PAMSStr.
    //PAMSClass<PAMSStr, PAMSInt> pamsclass((PAMSStr)PS_T,PAMSInt(1));
    /* This line will compile normally.  The difference between this and
     *   the first line above is that we cast the 'unsigned short' array
     *   to a 'unsigned short*' pointer when constructing the temporary.
    //PAMSClass<PAMSStr, PAMSInt> pamsclass(PAMSStr((unsigned
    int main() {
            return 0;

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Place text of code in description in a file named test.cpp
2. Run g++ test.cpp -o test
3. Note compile failure  (test.cpp:23: parse error before `1')

Actual Results:  The compiler produced the following error and failed to produce
the intended executable:

test.cpp:23: parse error before `1'

Expected Results:  No errors should have been produced and an executable should
have been created.

Additional info:

The included file contains workarounds to the problem which help to narrow down
the area of the bug.  Please try both workarounds to ensure they compile
correctly.  The bug looks to be contained to the construction of temporary
objects when being used as arguments to a template class constructor when an
arguement to the temporary constructor is an array where a pointer is expected.
Comment 1 Jakub Jelinek 2003-09-08 06:23:13 EDT
This seems to be fixed in gcc 3.4's new C++ parser (fails in gcc-2.96-rh,
gcc-3.0.x .. gcc-3.3.x).
Comment 2 Richard Henderson 2004-10-03 23:32:32 EDT
Indeed, fixed in gcc 3.4.
Comment 3 Richard Henderson 2004-10-03 23:33:24 EDT
Oops, didn't mean to close 2.1AS bug.
Comment 4 Jakub Jelinek 2004-10-07 10:36:21 EDT
I don't think it is going to be fixed in older compilers though.

Note You need to log in before you can comment on or make changes to this bug.