c++/909: Spurious error using nested classes in constructor calls
rmgiroux@hotmail.com
rmgiroux@hotmail.com
Mon Nov 27 12:36:00 GMT 2000
>Number: 909
>Category: c++
>Synopsis: Spurious error using nested classes in constructor calls
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Nov 27 12:36:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: rmgiroux@hotmail.com
>Release: gcc version 2.95.2 19991024 (release), gcc version 2.97 20001120 (experimental)
>Organization:
>Environment:
Linux
>Description:
Given a nested class, an attempt to construct an object using a constructor taking a reference of type "const A::Nested &" and another argument fails. Defaulting the second argument succeeds, letting the Nested object be implicitly constructed succeeds. Using an old-style cast
for either the argument to the nested type constructor or the nested type constructor also succeed. WIERD!
A a(A::Nested(i), Z); // ERROR: type specifier omitted
// for parameter
A b(A::Nested(int(i)), Z); // ERROR: type specifier omitted
// for parameter
A c(A::Nested((int)i), Z); // OK
>How-To-Repeat:
// Just compile this code
class A {
public:
struct Nested { Nested(int i) {} };
A(const Nested &n, int *p=0) ;
};
class B {
public:
B(const A::Nested &n, int *p=0);
B(const A &a, int *p=0);
};
int main(void)
{
int *Z=0;
int i=1;
A a(A::Nested(i), Z); // ERROR: type specifier omitted for parameter
A b(A::Nested(int(i)), Z); // ERROR: type specifier omitted for parameter
A c(A::Nested((int)i), Z); // OK
A d(A::Nested(1), Z); // OK
A e(A::Nested(i)); // OK
A f(i, Z); // OK
B g(A::Nested(i), Z); // ERROR: type specifier omitted for parameter
B h(i, Z); // OK
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list