D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3774 - should not be able to implicitly cast to private base class
Summary: should not be able to implicitly cast to private base class
Status: RESOLVED DUPLICATE of issue 2563
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2010-02-05 18:05 UTC by Walter Bright
Modified: 2014-02-15 13:13 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2010-02-05 18:05:00 UTC
It seems I have been testing this with a buggy c++ compiler or 
can't remember what was the problem previously. I now tried with gcc 
4.4.3 and this is how D and C++ differ:

---

class Foo {
  public:
  void bar() {}
};

class Bar : private Foo {
};

int main() {
  Foo *a = new Bar();
  a->bar();
}

test.cpp: In function ‘int main()’:
test.cpp:10: error: ‘Foo’ is an inaccessible base of ‘Bar’

---

module m1;

class Foo {
  public void bar() {}
}

class Bar : private foo {
}

module m2;
import m1;

void main() {
  Foo a = new Bar();
  a.bar();
}

// compiles and runs just fine
// Changing the 'Foo a = ...' into 'Bar a = ...' makes this an error
Comment 1 Stewart Gordon 2010-03-17 13:19:28 UTC

*** This issue has been marked as a duplicate of issue 2563 ***