OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [g++.old-deja/] [g++.law/] [visibility13.C] - Blame information for rev 154

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 149 jeremybenn
// { dg-do assemble  }
2
// GROUPS passed visibility
3
// visibility file
4
// From: dinh@cs.ucla.edu (Dinh Le)
5
// Date:     Mon, 12 Jul 93 22:21:06 -0700
6
// Subject:  class, template and their scoping problem
7
// Message-ID: <9307130521.AA18312@oahu.cs.ucla.edu>
8
 
9
#include 
10
#include 
11
 
12
//     ---------------   Array.h  &&  Array.cc   ------------------
13
 
14
using namespace std;
15
 
16
const int ArraySize = 12;
17
 
18
template 
19
class Array { // { dg-error "" } .struct Array_RC redecl.*
20
friend class Array_RC;
21
public:
22
    Array(const Type *ar, int sz) { init(ar,sz); }
23
    virtual ~Array() { delete [] ia; }
24
    virtual void print(ostream& = cout);
25
    virtual Type& operator[](int ix) { return ia[ix]; }
26
private:
27
    void init(const Type*, int);
28
    int size;
29
    int *ia;
30
};
31
 
32
template 
33
ostream& operator<<( ostream& os, Array& ar )
34
{
35
    ar.print(os);
36
    return os;
37
}
38
 
39
template 
40
void Array::print(ostream& os)
41
{
42
    const int lineLength = 12;
43
 
44
    os << "( " << size << " )< ";
45
    for (int ix = 0; ix < size; ++ix) {
46
        if (ix % lineLength == 0 && ix) os << "\n\t";
47
        os << ia[ ix ];
48
 
49
        if (ix % lineLength != lineLength-1 &&
50
            ix != size-1)
51
            os << ", ";
52
    }
53
    os << " >\n";
54
}
55
 
56
template 
57
void Array::init(const Type *array, int sz)
58
{
59
    ia = new Type[size = sz];
60
 
61
    for (int ix = 0; ix < size; ++ix)
62
        ia[ix] = (array!=0) ? array[ix] : (Type)0;
63
}
64
 
65
//     ---------------   Array_RC.h  &&  Array_RC.cc   ----------------
66
 
67
template 
68
class Array_RC : public Array {
69
public:
70
    Array_RC(const Type *ar, int sz);
71
    Type& operator[](int ix);
72
};
73
 
74
template 
75
Array_RC::Array_RC(const Type *ar, int sz) : Array(ar, sz) {}
76
 
77
template 
78
Type &Array_RC::operator[](int ix) {
79
    assert(ix >= 0 && ix < size);// { dg-error "" } member .size.*
80
    return ia[ix];// { dg-error "" } member .ia.*
81
}
82
 
83
//    -------------------   Test routine   ----------------------
84
 
85
template 
86
void try_array( Array &iA )
87
{
88
    cout << "try_array: initial array values:\n";
89
    cout << iA << endl;
90
}
91
 
92
template 
93
inline void
94
try_array( Array_RC &rc )
95
{
96
    try_array( ((Array&)rc) );
97
}
98
 
99
int main()
100
{
101
    static int ia[10] = { 12, 7, 14, 9, 128, 17, 6, 3, 27, 5 };
102
    Array_RC iA(ia, 10);
103
 
104
    cout << "template Array_RC class" << endl;
105
    try_array(iA);
106
 
107
    return 0;
108
}
109
 
110
template class Array_RC;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.