]>
Commit | Line | Data |
---|---|---|
5384b728 | 1 | 2002-05-24 Jakub Jelinek <jakub@redhat.com> |
2 | ||
3 | PR c++/6794 | |
4 | * decl.c (cp_make_fname_decl): If outside of function, emit | |
5 | the variable immediately. | |
6 | * call.c (build_call): Avoid crashing when noreturn function | |
7 | is called outside of function context. | |
8 | ||
9 | * g++.dg/ext/pretty1.C: New test. | |
10 | * g++.dg/ext/pretty2.C: New test. | |
11 | ||
12 | --- gcc/cp/decl.c.jj Tue May 21 20:27:10 2002 | |
13 | +++ gcc/cp/decl.c Fri May 24 17:28:16 2002 | |
14 | @@ -6772,7 +6772,10 @@ cp_make_fname_decl (id, type_dep) | |
15 | TREE_USED (decl) = 1; | |
16 | ||
17 | cp_finish_decl (decl, init, NULL_TREE, LOOKUP_ONLYCONVERTING); | |
18 | - | |
19 | + | |
20 | + if (!current_function_decl) | |
21 | + rest_of_decl_compilation (decl, 0, 1, 0); | |
22 | + | |
23 | return decl; | |
24 | } | |
25 | ||
26 | --- gcc/cp/call.c.jj Mon Apr 15 14:48:51 2002 | |
27 | +++ gcc/cp/call.c Fri May 24 12:49:22 2002 | |
28 | @@ -408,7 +408,7 @@ build_call (function, parms) | |
29 | nothrow = ((decl && TREE_NOTHROW (decl)) | |
30 | || TYPE_NOTHROW_P (TREE_TYPE (TREE_TYPE (function)))); | |
31 | ||
32 | - if (decl && TREE_THIS_VOLATILE (decl)) | |
33 | + if (decl && TREE_THIS_VOLATILE (decl) && current_function_decl) | |
34 | current_function_returns_abnormally = 1; | |
35 | ||
36 | if (decl && TREE_DEPRECATED (decl)) | |
37 | --- gcc/testsuite/g++.dg/ext/pretty1.C.jj Fri May 24 18:09:27 2002 | |
38 | +++ gcc/testsuite/g++.dg/ext/pretty1.C Fri May 24 18:13:10 2002 | |
39 | @@ -0,0 +1,67 @@ | |
40 | +// PR c++/6794 | |
41 | +// Test whether __PRETTY_FUNCTION__ works in templates, functions and | |
42 | +// in initializers at global scope | |
43 | +// { dg-do compile } | |
44 | +// { dg-options "" } | |
45 | + | |
46 | +extern "C" void __assert_fail (const char *, const char *, | |
47 | + unsigned int, const char *) | |
48 | + throw() __attribute__((noreturn)); | |
49 | +extern "C" void abort (void); | |
50 | +extern "C" void exit (int); | |
51 | + | |
52 | +#define str(expr) #expr | |
53 | +#define assert(expr) \ | |
54 | + ((expr) ? 0 : (__assert_fail (str(expr), __FILE__, __LINE__, \ | |
55 | + __PRETTY_FUNCTION__), 0)) | |
56 | + | |
57 | +int __attribute__((noinline)) | |
58 | +foo (void) | |
59 | +{ | |
60 | + return 1; | |
61 | +} | |
62 | + | |
63 | +template<class T> int | |
64 | +bar (T) | |
65 | +{ | |
66 | + return (assert (foo ()), 1); | |
67 | +} | |
68 | + | |
69 | +template<> int | |
70 | +bar<int> (int) | |
71 | +{ | |
72 | + return (assert (foo ()), 2); | |
73 | +} | |
74 | + | |
75 | +int a = (assert (foo ()), 1); | |
76 | +int b = (assert (foo ()), 2); | |
77 | + | |
78 | +int | |
79 | +main () | |
80 | +{ | |
81 | + double c = 1.0; | |
82 | + unsigned char *d = 0; | |
83 | + int e = (assert (foo ()), 3); | |
84 | + | |
85 | + bar (c); | |
86 | + bar (d); | |
87 | + bar (e); | |
88 | +} | |
89 | + | |
90 | +namespace N | |
91 | +{ | |
92 | + int f = (assert (foo ()), 4); | |
93 | +} | |
94 | + | |
95 | +void __attribute__((noinline)) | |
96 | +__assert_fail (const char *cond, const char *file, unsigned int line, | |
97 | + const char *pretty) throw () | |
98 | +{ | |
99 | + abort (); | |
100 | +} | |
101 | + | |
102 | +// { dg-final { scan-assembler "int bar\\(T\\).*with T = int" } } | |
103 | +// { dg-final { scan-assembler "top level" } } | |
104 | +// { dg-final { scan-assembler "int main\\(\\)" } } | |
105 | +// { dg-final { scan-assembler "int bar\\(T\\).*with T = double" } } | |
106 | +// { dg-final { scan-assembler "int bar\\(T\\).*with T = unsigned char\*" } } | |
107 | --- gcc/testsuite/g++.dg/ext/pretty2.C.jj Fri May 24 18:09:27 2002 | |
108 | +++ gcc/testsuite/g++.dg/ext/pretty2.C Fri May 24 18:13:42 2002 | |
109 | @@ -0,0 +1,61 @@ | |
110 | +// PR c++/6794 | |
111 | +// Test whether __PRETTY_FUNCTION__ works in templates, functions and | |
112 | +// in initializers at global scope | |
113 | +// { dg-do run } | |
114 | +// { dg-options "" } | |
115 | + | |
116 | +extern "C" void __assert_fail (const char *, const char *, | |
117 | + unsigned int, const char *) | |
118 | + throw() __attribute__((noreturn)); | |
119 | +extern "C" void abort (void); | |
120 | +extern "C" void exit (int); | |
121 | + | |
122 | +#define str(expr) #expr | |
123 | +#define assert(expr) \ | |
124 | + ((expr) ? 0 : (__assert_fail (str(expr), __FILE__, __LINE__, \ | |
125 | + __PRETTY_FUNCTION__), 0)) | |
126 | + | |
127 | +int __attribute__((noinline)) | |
128 | +foo (void) | |
129 | +{ | |
130 | + return 1; | |
131 | +} | |
132 | + | |
133 | +template<class T> int | |
134 | +bar (T) | |
135 | +{ | |
136 | + return (assert (foo ()), 1); | |
137 | +} | |
138 | + | |
139 | +template<> int | |
140 | +bar<int> (int) | |
141 | +{ | |
142 | + return (assert (foo ()), 2); | |
143 | +} | |
144 | + | |
145 | +int a = (assert (foo ()), 1); | |
146 | +int b = (assert (foo ()), 2); | |
147 | + | |
148 | +int | |
149 | +main () | |
150 | +{ | |
151 | + double c = 1.0; | |
152 | + unsigned char *d = 0; | |
153 | + int e = (assert (foo ()), 3); | |
154 | + | |
155 | + bar (c); | |
156 | + bar (d); | |
157 | + bar (e); | |
158 | +} | |
159 | + | |
160 | +namespace N | |
161 | +{ | |
162 | + int f = (assert (foo ()), 4); | |
163 | +} | |
164 | + | |
165 | +void __attribute__((noinline)) | |
166 | +__assert_fail (const char *cond, const char *file, unsigned int line, | |
167 | + const char *pretty) throw () | |
168 | +{ | |
169 | + abort (); | |
170 | +} |