Fixed parsing stack frames mentioning "operator<<" or "operator<".
[kdbg.git] / kdbg / testprogs / templates.cpp
bloba667463a0f73fabd56514c023d9f949f5644ae4e
1 // This file test stack parsing capabilities of KDbg.
2 // Parsing function names can be quite tricky ;)
3 #include <iostream>
4 using namespace std;
6 struct S {
7 void operator>>(int)
9 cout << __PRETTY_FUNCTION__ << endl;
13 template<typename T>
14 struct templS {
15 void operator>(T)
17 cout << __PRETTY_FUNCTION__ << endl;
19 void operator<(T)
21 cout << __PRETTY_FUNCTION__ << endl;
26 namespace A {
27 namespace {
28 namespace B {
29 namespace {
30 namespace {
31 void g()
33 cout << __PRETTY_FUNCTION__ << endl;
35 } // namespace
36 void Banong() { g(); }
37 } // namespace
38 void g() { Banong(); }
39 } // namespace B
40 void Aanong() { B::g(); }
41 } // namespace
42 void g() { Aanong(); }
44 void operator<<(int, S)
46 cout << __PRETTY_FUNCTION__ << endl;
49 template<typename T>
50 void operator<(T, S)
52 cout << __PRETTY_FUNCTION__ << endl;
54 } // namespace A
56 void operator<<(struct S&, int)
58 cout << __PRETTY_FUNCTION__ << endl;
61 template<typename T, typename U>
62 void operator<<(T&, U)
64 cout << __PRETTY_FUNCTION__ << endl;
67 void operator<(struct S&, int)
69 cout << __PRETTY_FUNCTION__ << endl;
72 template<typename T, typename U>
73 void operator<(T&, U)
75 cout << __PRETTY_FUNCTION__ << endl;
78 void f(const char* s)
80 A::g();
81 cout << s << endl;
84 template<typename T>
85 void indirect(T f, const char* s)
87 f(s);
90 int main()
92 S s1, s2;
93 f("direct");
94 s1 << 1;
95 s1 << s2;
96 s1 < 1;
97 s1 < s2;
99 A::operator<<(1, s1);
100 A::operator<(1, s1);
102 // the next lines test a templated function that accepts
103 // as one of its parameters a templated function pointer
104 void (*op1)(S&, S*) = operator<<;
105 operator<<(op1, s2);
106 void (*op2)(S&, S*) = operator<;
107 operator<(op2, s2);
108 indirect(f, "indirect");
110 // pointer to member function
111 void (S::*pm1)(int) = &S::operator>>;
112 (s1.*pm1)(1);
113 void (templS<int>::*pm2)(int) = &templS<int>::operator>;
114 templS<int> tSi;
115 (tSi.*pm2)(1);
116 tSi.operator<(1);