c++/1914: parse error at template default arg in ctor
Richard.Kreckel@Uni-Mainz.DE
Richard.Kreckel@Uni-Mainz.DE
Sun Apr 1 00:00:00 GMT 2001
>Number: 1914
>Category: c++
>Synopsis: parse error at template default arg in ctor
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 08 10:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Richard Kreckel
>Release: gcc-2.95.2 till sn-20010205
>Organization:
>Environment:
Debian GNU/Linux (potato)
>Description:
Please run the following program thru gcc:
#include <utility> // defines pair template
#include <iostream>
using namespace std;
typedef pair<int, int> ijpair;
class foo {
public:
// this does not work,...
// foo( pair < int, int > ij = pair < int, int > ( 0, 0 ) ) : indices ( ij ) { }
// ...but this does:
foo( pair<int,int> ij = ijpair(0,0) ) : indices(ij) { }
void displayme() { cout << indices.first << ',' << indices.second << endl; }
private:
pair<int, int> indices;
};
int pairsum(pair<int,int> ij = pair<int,int>(0,0))
{
return ij.first+ij.second;
}
int main(void)
{
foo f1 = foo(pair<int, int>(42,7));
foo f2 = foo();
f1.displayme();
f2.displayme();
cout << pairsum() << endl;
return 0;
}
The ctor with a default argument causes a parse error, but only
if we say pair<int, int>, and it works if we use the typedefed
ijpair. It is somewhat confusing that it works for the function
call, though. I first thought that a digraph or trigraph is
hitting me but inserting spaces does not help at all. I tried
the above example on Portland Group C++ compiler 3.1-3,
SGI MIPSpro 7.30, Compaq C V6.1 and a compiler by HP where it
worked fine with the ctor with default pair<int, int>.
>How-To-Repeat:
>Fix:
unknown
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list