Bug 38485 - [4.4 Regression] GCC can't parse a parenthesized comma in a template-id within a default argument
Summary: [4.4 Regression] GCC can't parse a parenthesized comma in a template-id withi...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-11 12:35 UTC by Michal Svoboda
Modified: 2008-12-18 15:55 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-12 06:54:50


Attachments
the faulty .ii file (77.10 KB, application/octet-stream)
2008-12-11 12:35 UTC, Michal Svoboda
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Svoboda 2008-12-11 12:35:10 UTC
Compressed .ii file goes as attachment.

gcc 4.3.2: (reports no errors)

my gcc:

g++ -c kded_kephal_automoc.ii

In file included from /src/a/kde/4.1.80/o/kdebase-workplace/libs/kephal/kded_kephal/moc_xmlconfigurations.cpp:11,
                 from /src/a/kde/4.1.80/o/kdebase-workplace/libs/kephal/kded_kephal/kded_kephal_automoc.cpp:6:
/src/a/kde/4.1.80/o/kdebase-workplace/libs/kephal/kded_kephal/../../../../../kdebase-workspace-4.1.80/libs/kephal/configurations/xml/xmlconfigurations.h:104: error: expected primary-expression at end of input

g++ -v

Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../svn/configure --prefix=/usr --enable-threads --enable-shared --enable-languages=c,c++ --host=x86_64-unknown-linux-gnu --with-system-zlib --with-x --enable-java-awt=gtk --enable-targets=x86_64-unknown-linux-gnu --with-arch=athlon64 --with-tune=athlon64 --with-cpu=athlon64 --disable-multilib --enable-__cxa_atexit --enable-libada --enable-gtk-cairo --enable-libgcj-multifile --with-long-double-128 --disable-nls
Thread model: posix
gcc version 4.4.0 20081211 (experimental) (GCC) 

The problem is at line 9355 of the .ii: (comment it out and it works)

void translateToOther(QMap<int, QRect> & layout, Output * base, QMap
<int, int> match = (QMap<int, int>()));

...and from what I could figure out, it is the right-side of the '=' default parameter assignment.

From my understanding, the code sould be equivalent to this small test case:

template <typename T1, typename T2> class blah {
        T1 whatever1;
        T2 whatever2;
        public:
        inline blah() {}
        inline T1 get1() { return whatever1; }
};

int foo(blah <int, int> bar = (blah <int, int> ())) {
        return bar.get1();
}

int main(void) {
        return foo();
}

However, this code compiles and runs perfectly on my gcc.
Comment 1 Michal Svoboda 2008-12-11 12:35:56 UTC
Created attachment 16883 [details]
the faulty .ii file
Comment 2 Andrew Pinski 2008-12-12 00:28:15 UTC
Reduced testcase:

template <class Key, class T>
class QMap { };

class XMLConfigurations {
  void translateToOther(QMap<int, int> match = (QMap<int, int>()));
};


Comment 3 Andrew Pinski 2008-12-12 00:29:40 UTC
Related to PR 57, one of the oldest GCC bugs which are still opened (there is a defect report against the C++ standard and that is why it is still opened).
Comment 4 Andrew Pinski 2008-12-12 00:31:47 UTC
Jason since you changed this area for 4.4, do you know if this is valid code or not?  Comment #2 contains the reduced testcase.

Thanks,
Andrew Pinski
Comment 5 Jason Merrill 2008-12-12 06:55:36 UTC
I think this testcase is clearly valid.
Comment 6 Jason Merrill 2008-12-18 15:55:25 UTC
Fixed.
Comment 7 Jason Merrill 2008-12-18 15:56:25 UTC
Subject: Bug 38485

Author: jason
Date: Thu Dec 18 15:54:59 2008
New Revision: 142815

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142815
Log:
        PR c++/38485
        * parser.c (cp_parser_token_starts_cast_expression): An EOF
        can't start a cast-expression.

Added:
    trunk/gcc/testsuite/g++.dg/parse/defarg13.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c
    trunk/gcc/testsuite/ChangeLog