summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.law/visibility17.C
blob: 67ef8927a634dd1f5f9e289f1c7edbd1f97ed3f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// { dg-do assemble  }
// GROUPS passed visibility
// visibility file
// From: Sandeep Shroff <ss@caere.com>
// Date:     Thu, 05 Aug 1993 17:23:20 -0700
// Subject:  Access to private constructor.
// Message-ID: <9308060023.AA10283@neptune.caere.com>
#include <iostream>
#include <cstring>

class Base
{
public:
  char* getName() {return name_;}

private:
  Base();
  Base(char* str);

  char* name_;
};

class Derived : public Base
{
public:
  Derived(int n, char* str);
  Derived(int n);

  int getNum() {return num_;}
private:
  int num_;
};

Base::Base() // { dg-error "is private" }
{
  name_ = std::strcpy(new char[std::strlen(" ") + 1], " ");
}

Base::Base(char* str) // { dg-error "is private" }
{
  if(str != NULL)
    name_ = std::strcpy(new char[std::strlen(str) + 1], str);
}

Derived::Derived(int n, char* str) : Base(str) // { dg-error "within this context" }
{
  num_ = n;
}

Derived::Derived(int n) : Base() // { dg-error "within this context" }
{
  num_ = n;
}



int main()
{
  // Derived* d = new Derived(10, "test");
  Derived* d = new Derived(10);

  std::cerr << d->getNum() << "\t" << d->getName() << std::endl;
}