OSDN Git Service

PR c++/8316, c++/9315, c++/10136
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.ext / pretty2.C
1 // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
2 // Contributed by Nathan Sidwell 21 Nov 1999 <nathan@acm.org>
3
4 // make sure __FUNCTION__ and __PRETTY_FUNCTION__ work in member functions
5
6 #include <stdio.h>
7 #include <string.h>
8
9 static bool bad = false;
10
11 struct X
12 {
13   X ();
14   ~X ();
15   void fn ();
16   operator int ();
17 };
18
19 X::X ()
20 {
21   char const *function = __FUNCTION__;
22   char const *pretty = __PRETTY_FUNCTION__;
23   
24   printf ("ctor\n");
25   printf ("__FUNCTION__ %s\n", function);
26   printf ("__PRETTY_FUNCTION__ %s\n", pretty);
27   
28   if (strcmp (function, "X"))
29     bad = true;
30   if (strcmp (pretty, "X::X()"))
31     bad = true;
32 }
33 X::~X ()
34 {
35   char const *function = __FUNCTION__;
36   char const *pretty = __PRETTY_FUNCTION__;
37   
38   printf ("dtor\n");
39   printf ("__FUNCTION__ %s\n", function);
40   printf ("__PRETTY_FUNCTION__ %s\n", pretty);
41   
42   if (strcmp (function, "X"))
43     bad = true;
44   if (strcmp (pretty, "X::~X()"))
45     bad = true;
46 }
47 void X::fn ()
48 {
49   char const *function = __FUNCTION__;
50   char const *pretty = __PRETTY_FUNCTION__;
51   
52   printf ("member fn\n");
53   printf ("__FUNCTION__ %s\n", function);
54   printf ("__PRETTY_FUNCTION__ %s\n", pretty);
55   
56   if (strcmp (function, "fn"))
57     bad = true;
58   if (strcmp (pretty, "void X::fn()"))
59     bad = true;
60 }
61 X::operator int ()
62 {
63   char const *function = __FUNCTION__;
64   char const *pretty = __PRETTY_FUNCTION__;
65   
66   printf ("conversion\n");
67   printf ("__FUNCTION__ %s\n", function);
68   printf ("__PRETTY_FUNCTION__ %s\n", pretty);
69   
70   if (strcmp (function, "operator i"))
71     bad = true;
72   if (strcmp (pretty, "X::operator int()"))
73     bad = true;
74   return 0;
75 }
76
77 int main ()
78 {
79   {
80     X x;
81     
82     x.fn ();
83     (void)int (x);
84   }
85   return bad;
86 }