Bug 15980 - parse error caused by default initializer for a template type function argument
Summary: parse error caused by default initializer for a template type function argument
Status: RESOLVED DUPLICATE of bug 57
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-13 22:42 UTC by Christian Schoenebeck
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Schoenebeck 2004-06-13 22:42:02 UTC
We encountered that gcc fails to compile with a parse error if a template 
based function argument is assigned a default initializer in the function 
prototype. Here is a stand alone test case for the exact problem: 
 
 
#define BUG 
 
template<typename A, typename B> 
struct C {}; 
  
typedef C<int, int> C_int_int; 
  
int w_typedef(C<int,int> arg = C_int_int()) { 
        return 0; 
} 
  
int wo_typedef(C<int,int> arg = C<int,int>()) { 
        return 0; 
} 
  
struct S { 
        int w_typedef(C_int_int arg = C_int_int()) { 
                return 0; 
        } 
  
        #ifdef BUG 
        int wo_typedef(C<int, int> arg = C<int,int>()) { 
                return 0; 
        } 
        #endif 
}; 
  
int main(int argc, char* argv[]) { 
        w_typedef(); 
        wo_typedef(); 
  
        S s; 
        s.w_typedef(); 
        #ifdef BUG 
        s.wo_typedef(); 
        #endif 
  
        return 0; 
} 
 
 
It compiles fine when BUG is not defined though. This code failed with 
gcc 3.2.2, 3.3.3 and also with 3.4, using various distributions (e.g. Debian 
and RedHat).
Comment 1 Andrew Pinski 2004-06-13 22:55:18 UTC
This is a dup of bug 57, one of the oldest bugs in GCC which is suspended because there is a DR report 
about the problem and no can agrue of what the standard says.

A simple workaround is to do: 
        int wo_typedef(C<int, int> arg = (C<int,int>()))

note the parentheses around the default argument.

*** This bug has been marked as a duplicate of 57 ***
Comment 2 Christian Schoenebeck 2004-06-13 23:22:21 UTC
Does it? Trying your proposed workaround gives me a "parse error before `;' 
token" (currently tested with gcc 3.2.2). 
Comment 3 Andrew Pinski 2004-06-13 23:26:47 UTC
oh, the workaround only works on 3.4.0 and above then.