Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.law/visibility17.C

raw
1 // { dg-do assemble }
2 // { dg-skip-if "requires hosted libstdc++ for iostream" { ! hostedlib } }
3 // GROUPS passed visibility
4 // visibility file
5 // From: Sandeep Shroff <[email protected]>
6 // Date: Thu, 05 Aug 1993 17:23:20 -0700
7 // Subject: Access to private constructor.
8 // Message-ID: <[email protected]>
9 #include <iostream>
10 #include <cstring>
11
12 class Base
13 {
14 public:
15 char* getName() {return name_;}
16
17 private:
18 Base();
19 Base(char* str);
20
21 char* name_;
22 };
23
24 class Derived : public Base
25 {
26 public:
27 Derived(int n, char* str);
28 Derived(int n);
29
30 int getNum() {return num_;}
31 private:
32 int num_;
33 };
34
35 Base::Base() // { dg-message "private" }
36 {
37 name_ = std::strcpy(new char[std::strlen(" ") + 1], " ");
38 }
39
40 Base::Base(char* str) // { dg-message "private" }
41 {
42 if(str != NULL)
43 name_ = std::strcpy(new char[std::strlen(str) + 1], str);
44 }
45
46 Derived::Derived(int n, char* str) : Base(str) // { dg-error "within this context" }
47 {
48 num_ = n;
49 }
50
51 Derived::Derived(int n) : Base() // { dg-error "within this context" }
52 {
53 num_ = n;
54 }
55
56
57
58 int main()
59 {
60 // Derived* d = new Derived(10, "test");
61 Derived* d = new Derived(10);
62
63 std::cerr << d->getNum() << "\t" << d->getName() << std::endl;
64 }
65
66
67