Gentoo Archives: gentoo-commits

From: "Sergei Trofimovich (slyfox)" <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-util/include-what-you-use/files: include-what-you-use-3.3-issue-110-elaboration.patch
Date: Fri, 27 Sep 2013 09:54:28
Message-Id: 20130927095425.7320E20034@flycatcher.gentoo.org
1 slyfox 13/09/27 09:54:25
2
3 Added:
4 include-what-you-use-3.3-issue-110-elaboration.patch
5 Log:
6 A tool to find for exact includes used by C/C++ sources. Warns about not only missing but also redundant ones!
7
8 (Portage version: 2.2.7/cvs/Linux x86_64, signed Manifest commit with key 611FF3AA)
9
10 Revision Changes Path
11 1.1 dev-util/include-what-you-use/files/include-what-you-use-3.3-issue-110-elaboration.patch
12
13 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/include-what-you-use/files/include-what-you-use-3.3-issue-110-elaboration.patch?rev=1.1&view=markup
14 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-util/include-what-you-use/files/include-what-you-use-3.3-issue-110-elaboration.patch?rev=1.1&content-type=text/plain
15
16 Index: include-what-you-use-3.3-issue-110-elaboration.patch
17 ===================================================================
18 Upstream-bug: http://code.google.com/p/include-what-you-use/issues/detail?id=110
19 Index: tests/elaboration-struct.h
20 ===================================================================
21 --- tests/elaboration-struct.h (revision 0)
22 +++ tests/elaboration-struct.h (revision 0)
23 @@ -0,0 +1,10 @@
24 +//===--- elaboration-struct.h - test input file for iwyu ------------------===//
25 +//
26 +// The LLVM Compiler Infrastructure
27 +//
28 +// This file is distributed under the University of Illinois Open Source
29 +// License. See LICENSE.TXT for details.
30 +//
31 +//===----------------------------------------------------------------------===//
32 +
33 +struct ElaborationStruct {};
34
35 Property changes on: tests\elaboration-struct.h
36 ___________________________________________________________________
37 Added: svn:eol-style
38 + native
39
40 Index: tests/elaboration.cc
41 ===================================================================
42 --- tests/elaboration.cc (revision 0)
43 +++ tests/elaboration.cc (revision 0)
44 @@ -0,0 +1,79 @@
45 +//===--- elaboration.cc - test input file for iwyu ------------------------===//
46 +//
47 +// The LLVM Compiler Infrastructure
48 +//
49 +// This file is distributed under the University of Illinois Open Source
50 +// License. See LICENSE.TXT for details.
51 +//
52 +//===----------------------------------------------------------------------===//
53 +
54 +// Test that elaborated types are handled correctly.
55 +//
56 +// An elaborated type is a type prefixed by type kind, e.g. 'class Foo',
57 +// 'struct Bar' or 'enum Baz'.
58 +//
59 +// Clang considers namespace-qualified types elaborated as well, even if they
60 +// lack actual elaboration, e.g. 'ns::Foo'.
61 +
62 +
63 +#include "tests/elaboration-enum1.h" // for ElaborationEnum1
64 +#include "tests/elaboration-enum2.h" // for ElaborationEnum2
65 +
66 +// Make sure both elaborated and bare enums require the full type.
67 +void bare_enum(ElaborationEnum1 e);
68 +void elaborated_enum(enum ElaborationEnum2 e);
69 +
70 +// For C++ classes, a forward declaration should suffice for
71 +// bare type names and nothing should be necessary for elaborated ones.
72 +#include "tests/elaboration-class.h"
73 +
74 +void bare_class(ElaborationClass* c);
75 +void elaborated_class(class UnknownElaborationClass* c);
76 +
77 +// Structs should work like classes.
78 +#include "tests/elaboration-struct.h"
79 +
80 +void bare_struct(ElaborationStruct* s);
81 +void elaborated_struct(struct UnknownElaborationStruct* s);
82 +
83 +// And unions.
84 +#include "tests/elaboration-union.h"
85 +
86 +void bare_union(ElaborationUnion* u);
87 +void elaborated_union(union UnknownElaborationUnion* u);
88 +
89 +// Namespace-qualified types must be forward-declared even
90 +// if they are represented as elaborated types in Clang's AST.
91 +#include "tests/elaboration-namespace.h"
92 +
93 +void namespace_qualified(Elaboration::Class* c);
94 +
95 +// We can use elaborated types for templates, too, but
96 +// they must also be forward-declared.
97 +struct Elaboration::Template<int, float>* namespace_qualified_template;
98 +
99 +/**** IWYU_SUMMARY
100 +
101 +tests/elaboration.cc should add these lines:
102 +class ElaborationClass;
103 +namespace Elaboration { class Class; }
104 +namespace Elaboration { template <typename T, typename U> struct Template; }
105 +struct ElaborationStruct;
106 +union ElaborationUnion;
107 +
108 +tests/elaboration.cc should remove these lines:
109 +- #include "tests/elaboration-class.h" // lines XX-XX
110 +- #include "tests/elaboration-namespace.h" // lines XX-XX
111 +- #include "tests/elaboration-struct.h" // lines XX-XX
112 +- #include "tests/elaboration-union.h" // lines XX-XX
113 +
114 +The full include-list for tests/elaboration.cc:
115 +#include "tests/elaboration-enum1.h" // for ElaborationEnum1
116 +#include "tests/elaboration-enum2.h" // for ElaborationEnum2
117 +class ElaborationClass;
118 +namespace Elaboration { class Class; }
119 +namespace Elaboration { template <typename T, typename U> struct Template; }
120 +struct ElaborationStruct;
121 +union ElaborationUnion;
122 +
123 +***** IWYU_SUMMARY */
124 Index: tests/elaboration-enum1.h
125 ===================================================================
126 --- tests/elaboration-enum1.h (revision 0)
127 +++ tests/elaboration-enum1.h (revision 0)
128 @@ -0,0 +1,13 @@
129 +//===--- elaboration-enum1.h - test input file for iwyu -------------------===//
130 +//
131 +// The LLVM Compiler Infrastructure
132 +//
133 +// This file is distributed under the University of Illinois Open Source
134 +// License. See LICENSE.TXT for details.
135 +//
136 +//===----------------------------------------------------------------------===//
137 +
138 +enum ElaborationEnum1 {
139 + EE1_First,
140 + EE1_Second
141 +};
142
143 Property changes on: tests\elaboration-enum1.h
144 ___________________________________________________________________
145 Added: svn:eol-style
146 + native
147
148 Index: tests/elaboration-class.h
149 ===================================================================
150 --- tests/elaboration-class.h (revision 0)
151 +++ tests/elaboration-class.h (revision 0)
152 @@ -0,0 +1,10 @@
153 +//===--- elaboration-class.h - test input file for iwyu -------------------===//
154 +//
155 +// The LLVM Compiler Infrastructure
156 +//
157 +// This file is distributed under the University of Illinois Open Source
158 +// License. See LICENSE.TXT for details.
159 +//
160 +//===----------------------------------------------------------------------===//
161 +
162 +class ElaborationClass {};
163
164 Property changes on: tests\elaboration-class.h
165 ___________________________________________________________________
166 Added: svn:eol-style
167 + native
168
169 Index: tests/badinc.cc
170 ===================================================================
171 --- tests/badinc.cc (revision 485)
172 +++ tests/badinc.cc (working copy)
173 @@ -317,17 +317,12 @@
174 // IWYU: I2_Class is...*badinc-i2.h.*for autocast
175 // IWYU: I2_Class needs a declaration
176 const I2_Class& i2,
177 - const class I1_Class& elaborated_i1,
178 - // IWYU: I2_Class is...*badinc-i2.h.*for autocast
179 - const class I2_Class& elaborated_i2,
180 // A subtle c++ point: forward-declaring is ok for i2b, because
181 // you can't do implicit conversion to a non-const reference
182 // (implicit conversion involves creating a temporary, which
183 // doesn't bind to non-const references).
184 // IWYU: I2_Class needs a declaration
185 I2_Class& i2_nonconst,
186 - class I2_Class& elaborated_i2_nonconst,
187 - struct i3_ns1::i3_ns2::i3_ns3::I3_ForwardDeclareNamespaceStruct* i3_forward,
188 // Forward-declaring is ok because we a const reference to a *pointer*.
189 // IWYU: I2_Class needs a declaration
190 I2_Class* const & i2_ptrref,
191 @@ -897,11 +892,6 @@
192 // IWYU: I3_ForwardDeclareNamespaceTemplateStruct needs a declaration
193 i3_ns1::i3_ns2::i3_ns3::I3_ForwardDeclareNamespaceTemplateStruct<H_Enum, 2>*
194 i3_fdtns_struct;
195 -// Even with elaboration, we still need fwd decl.
196 -// IWYU: I3_ForwardDeclareNamespaceTemplateStruct needs a declaration
197 -struct i3_ns1::i3_ns2::i3_ns3::I3_ForwardDeclareNamespaceTemplateStruct<H_Enum,
198 - 3>*
199 - i3_elaborated_fdtns_struct;
200
201 // IWYU: I3_UnnamedNamespaceStruct needs a declaration
202 i3_ns1::I3_UnnamedNamespaceStruct* i3_unnamed_namespace_struct;
203 Index: tests/elaboration-enum2.h
204 ===================================================================
205 --- tests/elaboration-enum2.h (revision 0)
206 +++ tests/elaboration-enum2.h (revision 0)
207 @@ -0,0 +1,13 @@
208 +//===--- elaboration-enum2.h - test input file for iwyu -------------------===//
209 +//
210 +// The LLVM Compiler Infrastructure
211 +//
212 +// This file is distributed under the University of Illinois Open Source
213 +// License. See LICENSE.TXT for details.
214 +//
215 +//===----------------------------------------------------------------------===//
216 +
217 +enum ElaborationEnum2 {
218 + EE2_First,
219 + EE2_Second
220 +};
221
222 Property changes on: tests\elaboration-enum2.h
223 ___________________________________________________________________
224 Added: svn:eol-style
225 + native
226
227 Index: tests/elaboration-union.h
228 ===================================================================
229 --- tests/elaboration-union.h (revision 0)
230 +++ tests/elaboration-union.h (revision 0)
231 @@ -0,0 +1,10 @@
232 +//===--- elaboration-union.h - test input file for iwyu -------------------===//
233 +//
234 +// The LLVM Compiler Infrastructure
235 +//
236 +// This file is distributed under the University of Illinois Open Source
237 +// License. See LICENSE.TXT for details.
238 +//
239 +//===----------------------------------------------------------------------===//
240 +
241 +union ElaborationUnion {};
242
243 Property changes on: tests\elaboration-union.h
244 ___________________________________________________________________
245 Added: svn:eol-style
246 + native
247
248 Index: tests/elaboration-namespace.h
249 ===================================================================
250 --- tests/elaboration-namespace.h (revision 0)
251 +++ tests/elaboration-namespace.h (revision 0)
252 @@ -0,0 +1,18 @@
253 +//===--- elaboration-namespace.h - test input file for iwyu ---------------===//
254 +//
255 +// The LLVM Compiler Infrastructure
256 +//
257 +// This file is distributed under the University of Illinois Open Source
258 +// License. See LICENSE.TXT for details.
259 +//
260 +//===----------------------------------------------------------------------===//
261 +
262 +namespace Elaboration {
263 + class Class {};
264 +
265 + template< typename T, typename U >
266 + struct Template {
267 + typedef T FirstType;
268 + typedef U SecondType;
269 + };
270 +}
271
272 Property changes on: tests\elaboration-namespace.h
273 ___________________________________________________________________
274 Added: svn:eol-style
275 + native
276
277 Index: iwyu.cc
278 ===================================================================
279 --- iwyu.cc (revision 485)
280 +++ iwyu.cc (working copy)
281 @@ -166,6 +166,7 @@
282 using clang::DeclContext;
283 using clang::DeclRefExpr;
284 using clang::ElaboratedType;
285 +using clang::EnumType;
286 using clang::Expr;
287 using clang::FileEntry;
288 using clang::FriendDecl;
289 @@ -3454,6 +3455,7 @@
290 preprocessor_info().FileInfoFor(CurrentFileEntry())->AddForwardDeclare(
291 decl_to_fwd_declare, definitely_keep_fwd_decl);
292 }
293 +
294 return Base::VisitTagDecl(decl);
295 }
296
297 @@ -3562,13 +3564,17 @@
298 // If we're forward-declarable, then no complicated checking is
299 // needed: just forward-declare. If we're already elaborated
300 // ('class Foo x') but not namespace-qualified ('class ns::Foo x')
301 - // there's no need even to forward-declare!
302 + // or an enum ('enum Foo x') there's no need even to forward-declare!
303 if (CanForwardDeclareType(current_ast_node())) {
304 current_ast_node()->set_in_forward_declare_context(true);
305 +
306 + bool is_enum_type = current_ast_node()->GetAs<EnumType>();
307 if (!IsElaborationNode(current_ast_node()->parent()) ||
308 - IsNamespaceQualifiedNode(current_ast_node()->parent())) {
309 + IsNamespaceQualifiedNode(current_ast_node()->parent()) ||
310 + is_enum_type) {
311 ReportDeclForwardDeclareUse(CurrentLoc(), type->getDecl());
312 }
313 +
314 return Base::VisitTagType(type);
315 }