blob: 2800df4caf5de0c79d7cdffd6fb618d8c6eb9b7a [file] [log] [blame]
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001//===- unittests/AST/DeclPrinterTest.cpp --- Declaration printer tests ----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains tests for Decl::print() and related methods.
11//
12// Search this file for WRONG to see test cases that are producing something
13// completely wrong, invalid C++ or just misleading.
14//
15// These tests have a coding convention:
16// * declaration to be printed is named 'A' unless it should have some special
17// name (e.g., 'operator+');
18// * additional helper declarations are 'Z', 'Y', 'X' and so on.
19//
20//===----------------------------------------------------------------------===//
21
22#include "clang/AST/ASTContext.h"
23#include "clang/ASTMatchers/ASTMatchFinder.h"
24#include "clang/Tooling/Tooling.h"
Daniel Jasper7fd90b02012-08-24 05:50:27 +000025#include "llvm/ADT/SmallString.h"
Dmitri Gribenko49795ae2012-08-20 23:39:06 +000026#include "gtest/gtest.h"
27
28using namespace clang;
29using namespace ast_matchers;
30using namespace tooling;
31
32namespace {
33
34void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D) {
35 PrintingPolicy Policy = Context->getPrintingPolicy();
Dmitri Gribenkod1fc82e2012-08-21 17:36:32 +000036 Policy.TerseOutput = true;
Dmitri Gribenko49795ae2012-08-20 23:39:06 +000037 D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
38}
39
40class PrintMatch : public MatchFinder::MatchCallback {
41 SmallString<1024> Printed;
42 unsigned NumFoundDecls;
43
44public:
45 PrintMatch() : NumFoundDecls(0) {}
46
47 virtual void run(const MatchFinder::MatchResult &Result) {
48 const Decl *D = Result.Nodes.getDeclAs<Decl>("id");
49 if (!D || D->isImplicit())
50 return;
51 NumFoundDecls++;
52 if (NumFoundDecls > 1)
53 return;
54
55 llvm::raw_svector_ostream Out(Printed);
56 PrintDecl(Out, Result.Context, D);
57 }
58
59 StringRef getPrinted() const {
60 return Printed;
61 }
62
63 unsigned getNumFoundDecls() const {
64 return NumFoundDecls;
65 }
66};
67
68bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code,
69 ArrayRef<const char *> ClangArgs) {
70 SmallString<16> FileNameStorage;
71 StringRef FileNameRef = "input.cc";
72
73 std::vector<std::string> ArgVector;
74 ArgVector.push_back("clang-tool");
75 ArgVector.push_back("-fsyntax-only");
Nico Weber50f88b92012-08-30 02:08:31 +000076 // operator delete (void*) grows a "noexcept" in c++11.
77 ArgVector.push_back("-std=c++98");
Dmitri Gribenko49795ae2012-08-20 23:39:06 +000078 ArgVector.push_back(FileNameRef.data());
79 for (unsigned i = 0, e = ClangArgs.size(); i != e; ++i)
80 ArgVector.push_back(ClangArgs[i]);
81
82 FileManager Files((FileSystemOptions()));
83 ToolInvocation Invocation(ArgVector, ToolAction, &Files);
84
85 SmallString<1024> CodeStorage;
86 Invocation.mapVirtualFile(FileNameRef,
87 Code.toNullTerminatedStringRef(CodeStorage));
88 return Invocation.run();
89}
90
91::testing::AssertionResult PrintedDeclMatches(
92 StringRef Code,
93 ArrayRef<const char *> ClangArgs,
94 const DeclarationMatcher &NodeMatch,
95 StringRef ExpectedPrinted) {
96 PrintMatch Printer;
97 MatchFinder Finder;
98 Finder.addMatcher(NodeMatch, &Printer);
99 OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder));
100
101 if (!runToolOnCode(Factory->create(), Code, ClangArgs))
102 return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
103
104 if (Printer.getNumFoundDecls() == 0)
105 return testing::AssertionFailure()
106 << "Matcher didn't find any declarations";
107
108 if (Printer.getNumFoundDecls() > 1)
109 return testing::AssertionFailure()
110 << "Matcher should match only one declaration "
111 "(found " << Printer.getNumFoundDecls() << ")";
112
113 if (Printer.getPrinted() != ExpectedPrinted)
114 return ::testing::AssertionFailure()
115 << "Expected \"" << ExpectedPrinted << "\", "
116 "got \"" << Printer.getPrinted() << "\"";
117
118 return ::testing::AssertionSuccess();
119}
120
121::testing::AssertionResult PrintedDeclMatches(StringRef Code,
122 StringRef DeclName,
123 StringRef ExpectedPrinted) {
124 return PrintedDeclMatches(Code,
125 ArrayRef<const char *>(),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000126 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000127 ExpectedPrinted);
128}
129
130::testing::AssertionResult PrintedDeclMatches(
131 StringRef Code,
132 const DeclarationMatcher &NodeMatch,
133 StringRef ExpectedPrinted) {
134 return PrintedDeclMatches(Code,
135 ArrayRef<const char *>(),
136 NodeMatch,
137 ExpectedPrinted);
138}
139
140::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
141 StringRef DeclName,
142 StringRef ExpectedPrinted) {
143 return PrintedDeclMatches(Code,
144 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000145 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000146 ExpectedPrinted);
147}
148
149::testing::AssertionResult PrintedDeclCXX11Matches(
150 StringRef Code,
151 const DeclarationMatcher &NodeMatch,
152 StringRef ExpectedPrinted) {
153 return PrintedDeclMatches(Code,
154 ArrayRef<const char *>("-std=c++11"),
155 NodeMatch,
156 ExpectedPrinted);
157}
158
159} // unnamed namespace
160
161TEST(DeclPrinter, TestNamespace1) {
162 ASSERT_TRUE(PrintedDeclMatches(
163 "namespace A { int B; }",
164 "A",
165 "namespace A {\n}"));
166 // Should be: with { ... }
167}
168
169TEST(DeclPrinter, TestNamespace2) {
170 ASSERT_TRUE(PrintedDeclCXX11Matches(
171 "inline namespace A { int B; }",
172 "A",
173 "inline namespace A {\n}"));
174 // Should be: with { ... }
175}
176
177TEST(DeclPrinter, TestNamespaceAlias1) {
178 ASSERT_TRUE(PrintedDeclMatches(
179 "namespace Z { }"
180 "namespace A = Z;",
181 "A",
182 "namespace A = Z"));
183 // Should be: with semicolon
184}
185
186TEST(DeclPrinter, TestNamespaceAlias2) {
187 ASSERT_TRUE(PrintedDeclMatches(
188 "namespace X { namespace Y {} }"
189 "namespace A = X::Y;",
190 "A",
191 "namespace A = X::Y"));
192 // Should be: with semicolon
193}
194
195TEST(DeclPrinter, TestCXXRecordDecl1) {
196 ASSERT_TRUE(PrintedDeclMatches(
197 "class A { int a; };",
198 "A",
199 "class A {\n}"));
200 // Should be: with semicolon, with { ... }
201}
202
203TEST(DeclPrinter, TestCXXRecordDecl2) {
204 ASSERT_TRUE(PrintedDeclMatches(
205 "struct A { int a; };",
206 "A",
207 "struct A {\n}"));
208 // Should be: with semicolon, with { ... }
209}
210
211TEST(DeclPrinter, TestCXXRecordDecl3) {
212 ASSERT_TRUE(PrintedDeclMatches(
213 "union A { int a; };",
214 "A",
215 "union A {\n}"));
216 // Should be: with semicolon, with { ... }
217}
218
219TEST(DeclPrinter, TestCXXRecordDecl4) {
220 ASSERT_TRUE(PrintedDeclMatches(
221 "class Z { int a; };"
222 "class A : Z { int b; };",
223 "A",
224 "class A : Z {\n}"));
225 // Should be: with semicolon, with { ... }, without two spaces
226}
227
228TEST(DeclPrinter, TestCXXRecordDecl5) {
229 ASSERT_TRUE(PrintedDeclMatches(
230 "struct Z { int a; };"
231 "struct A : Z { int b; };",
232 "A",
233 "struct A : Z {\n}"));
234 // Should be: with semicolon, with { ... }, without two spaces
235}
236
237TEST(DeclPrinter, TestCXXRecordDecl6) {
238 ASSERT_TRUE(PrintedDeclMatches(
239 "class Z { int a; };"
240 "class A : public Z { int b; };",
241 "A",
242 "class A : public Z {\n}"));
243 // Should be: with semicolon, with { ... }
244}
245
246TEST(DeclPrinter, TestCXXRecordDecl7) {
247 ASSERT_TRUE(PrintedDeclMatches(
248 "class Z { int a; };"
249 "class A : protected Z { int b; };",
250 "A",
251 "class A : protected Z {\n}"));
252 // Should be: with semicolon, with { ... }
253}
254
255TEST(DeclPrinter, TestCXXRecordDecl8) {
256 ASSERT_TRUE(PrintedDeclMatches(
257 "class Z { int a; };"
258 "class A : private Z { int b; };",
259 "A",
260 "class A : private Z {\n}"));
261 // Should be: with semicolon, with { ... }
262}
263
264TEST(DeclPrinter, TestCXXRecordDecl9) {
265 ASSERT_TRUE(PrintedDeclMatches(
266 "class Z { int a; };"
267 "class A : virtual Z { int b; };",
268 "A",
269 "class A : virtual Z {\n}"));
270 // Should be: with semicolon, with { ... }, without two spaces
271}
272
273TEST(DeclPrinter, TestCXXRecordDecl10) {
274 ASSERT_TRUE(PrintedDeclMatches(
275 "class Z { int a; };"
276 "class A : virtual public Z { int b; };",
277 "A",
278 "class A : virtual public Z {\n}"));
279 // Should be: with semicolon, with { ... }
280}
281
282TEST(DeclPrinter, TestCXXRecordDecl11) {
283 ASSERT_TRUE(PrintedDeclMatches(
284 "class Z { int a; };"
285 "class Y : virtual public Z { int b; };"
286 "class A : virtual public Z, private Y { int c; };",
287 "A",
288 "class A : virtual public Z, private Y {\n}"));
289 // Should be: with semicolon, with { ... }
290}
291
292TEST(DeclPrinter, TestFunctionDecl1) {
293 ASSERT_TRUE(PrintedDeclMatches(
294 "void A();",
295 "A",
296 "void A()"));
297 // Should be: with semicolon
298}
299
300TEST(DeclPrinter, TestFunctionDecl2) {
301 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000302 "void A() {}",
303 "A",
304 "void A()"));
305 // Should be: with semicolon
306}
307
308TEST(DeclPrinter, TestFunctionDecl3) {
309 ASSERT_TRUE(PrintedDeclMatches(
310 "void Z();"
311 "void A() { Z(); }",
312 "A",
313 "void A()"));
314 // Should be: with semicolon
315}
316
317TEST(DeclPrinter, TestFunctionDecl4) {
318 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000319 "extern void A();",
320 "A",
321 "extern void A()"));
322 // Should be: with semicolon
323}
324
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000325TEST(DeclPrinter, TestFunctionDecl5) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000326 ASSERT_TRUE(PrintedDeclMatches(
327 "static void A();",
328 "A",
329 "static void A()"));
330 // Should be: with semicolon
331}
332
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000333TEST(DeclPrinter, TestFunctionDecl6) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000334 ASSERT_TRUE(PrintedDeclMatches(
335 "inline void A();",
336 "A",
337 "inline void A()"));
338 // Should be: with semicolon
339}
340
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000341TEST(DeclPrinter, TestFunctionDecl7) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000342 ASSERT_TRUE(PrintedDeclCXX11Matches(
343 "constexpr int A(int a);",
344 "A",
345 "int A(int a)"));
346 // WRONG; Should be: "constexpr int A(int a);"
347}
348
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000349TEST(DeclPrinter, TestFunctionDecl8) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000350 ASSERT_TRUE(PrintedDeclMatches(
351 "void A(int a);",
352 "A",
353 "void A(int a)"));
354 // Should be: with semicolon
355}
356
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000357TEST(DeclPrinter, TestFunctionDecl9) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000358 ASSERT_TRUE(PrintedDeclMatches(
359 "void A(...);",
360 "A",
361 "void A(...)"));
362 // Should be: with semicolon
363}
364
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000365TEST(DeclPrinter, TestFunctionDecl10) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000366 ASSERT_TRUE(PrintedDeclMatches(
367 "void A(int a, ...);",
368 "A",
369 "void A(int a, ...)"));
370 // Should be: with semicolon
371}
372
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000373TEST(DeclPrinter, TestFunctionDecl11) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000374 ASSERT_TRUE(PrintedDeclMatches(
375 "typedef long size_t;"
376 "typedef int *pInt;"
377 "void A(int a, pInt b, size_t c);",
378 "A",
379 "void A(int a, pInt b, size_t c)"));
380 // Should be: with semicolon
381}
382
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000383TEST(DeclPrinter, TestFunctionDecl12) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000384 ASSERT_TRUE(PrintedDeclMatches(
385 "void A(int a, int b = 0);",
386 "A",
387 "void A(int a, int b = 0)"));
388 // Should be: with semicolon
389}
390
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000391TEST(DeclPrinter, TestFunctionDecl13) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000392 ASSERT_TRUE(PrintedDeclMatches(
393 "void (*A(int a))(int b);",
394 "A",
395 "void (*A(int a))(int)"));
396 // Should be: with semicolon, with parameter name (?)
397}
398
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000399TEST(DeclPrinter, TestFunctionDecl14) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000400 ASSERT_TRUE(PrintedDeclMatches(
401 "template<typename T>"
402 "void A(T t) { }"
403 "template<>"
404 "void A(int N) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000405 functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000406 "void A(int N)"));
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000407 // WRONG; Should be: "template <> void A(int N);"));
408}
409
410
411TEST(DeclPrinter, TestCXXConstructorDecl1) {
412 ASSERT_TRUE(PrintedDeclMatches(
413 "struct A {"
414 " A();"
415 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000416 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000417 ""));
418 // WRONG; Should be: "A();"
419}
420
421TEST(DeclPrinter, TestCXXConstructorDecl2) {
422 ASSERT_TRUE(PrintedDeclMatches(
423 "struct A {"
424 " A(int a);"
425 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000426 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000427 ""));
428 // WRONG; Should be: "A(int a);"
429}
430
431TEST(DeclPrinter, TestCXXConstructorDecl3) {
432 ASSERT_TRUE(PrintedDeclMatches(
433 "struct A {"
434 " A(const A &a);"
435 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000436 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000437 ""));
438 // WRONG; Should be: "A(const A &a);"
439}
440
441TEST(DeclPrinter, TestCXXConstructorDecl4) {
442 ASSERT_TRUE(PrintedDeclMatches(
443 "struct A {"
444 " A(const A &a, int = 0);"
445 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000446 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000447 ""));
448 // WRONG; Should be: "A(const A &a, int = 0);"
449}
450
451TEST(DeclPrinter, TestCXXConstructorDecl5) {
452 ASSERT_TRUE(PrintedDeclCXX11Matches(
453 "struct A {"
454 " A(const A &&a);"
455 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000456 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000457 ""));
458 // WRONG; Should be: "A(const A &&a);"
459}
460
461TEST(DeclPrinter, TestCXXConstructorDecl6) {
462 ASSERT_TRUE(PrintedDeclMatches(
463 "struct A {"
464 " explicit A(int a);"
465 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000466 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000467 ""));
468 // WRONG; Should be: "explicit A(int a);"
469}
470
471TEST(DeclPrinter, TestCXXConstructorDecl7) {
472 ASSERT_TRUE(PrintedDeclMatches(
473 "struct A {"
474 " constexpr A();"
475 "};",
476 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000477 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000478 ""));
479 // WRONG; Should be: "constexpr A();"
480}
481
482TEST(DeclPrinter, TestCXXConstructorDecl8) {
483 ASSERT_TRUE(PrintedDeclMatches(
484 "struct A {"
485 " A() = default;"
486 "};",
487 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000488 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000489 ""));
490 // WRONG; Should be: "A() = default;"
491}
492
493TEST(DeclPrinter, TestCXXConstructorDecl9) {
494 ASSERT_TRUE(PrintedDeclMatches(
495 "struct A {"
496 " A() = delete;"
497 "};",
498 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000499 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000500 " = delete"));
501 // WRONG; Should be: "A() = delete;"
502}
503
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000504TEST(DeclPrinter, TestCXXConstructorDecl10) {
505 ASSERT_TRUE(PrintedDeclCXX11Matches(
506 "template<typename... T>"
507 "struct A {"
508 " A(const A &a);"
509 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000510 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000511 ""));
512 // WRONG; Should be: "A(const A &a);"
513}
514
NAKAMURA Takumi29b1f682012-08-25 00:05:56 +0000515#if !defined(_MSC_VER)
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000516TEST(DeclPrinter, TestCXXConstructorDecl11) {
517 ASSERT_TRUE(PrintedDeclCXX11Matches(
518 "template<typename... T>"
519 "struct A : public T... {"
520 " A(T&&... ts) : T(ts)... {}"
521 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000522 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000523 "A<T...>(T &&ts...) : T(ts)"));
Dmitri Gribenkof6ec15a2012-08-24 00:27:50 +0000524 // WRONG; Should be: "A(T&&... ts) : T(ts)..."
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000525}
NAKAMURA Takumi29b1f682012-08-25 00:05:56 +0000526#endif
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000527
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000528TEST(DeclPrinter, TestCXXDestructorDecl1) {
529 ASSERT_TRUE(PrintedDeclMatches(
530 "struct A {"
531 " ~A();"
532 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000533 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000534 "void ~A()"));
535 // WRONG; Should be: "~A();"
536}
537
538TEST(DeclPrinter, TestCXXDestructorDecl2) {
539 ASSERT_TRUE(PrintedDeclMatches(
540 "struct A {"
541 " virtual ~A();"
542 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000543 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000544 "virtual void ~A()"));
545 // WRONG; Should be: "virtual ~A();"
546}
547
548TEST(DeclPrinter, TestCXXConversionDecl1) {
549 ASSERT_TRUE(PrintedDeclMatches(
550 "struct A {"
551 " operator int();"
552 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000553 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000554 "int operator int()"));
555 // WRONG; Should be: "operator int();"
556}
557
558TEST(DeclPrinter, TestCXXConversionDecl2) {
559 ASSERT_TRUE(PrintedDeclMatches(
560 "struct A {"
561 " operator bool();"
562 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000563 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000564 "bool operator _Bool()"));
565 // WRONG; Should be: "operator bool();"
566}
567
568TEST(DeclPrinter, TestCXXConversionDecl3) {
569 ASSERT_TRUE(PrintedDeclMatches(
570 "struct Z {};"
571 "struct A {"
572 " operator Z();"
573 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000574 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000575 "Z operator struct Z()"));
576 // WRONG; Should be: "operator Z();"
577}
578
579TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
580 ASSERT_TRUE(PrintedDeclMatches(
581 "namespace std { typedef decltype(sizeof(int)) size_t; }"
582 "struct Z {"
583 " void *operator new(std::size_t);"
584 "};",
585 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000586 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000587 "void *operator new(std::size_t)"));
588 // Should be: with semicolon
589}
590
591TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
592 ASSERT_TRUE(PrintedDeclMatches(
593 "namespace std { typedef decltype(sizeof(int)) size_t; }"
594 "struct Z {"
595 " void *operator new[](std::size_t);"
596 "};",
597 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000598 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000599 "void *operator new[](std::size_t)"));
600 // Should be: with semicolon
601}
602
603TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
604 ASSERT_TRUE(PrintedDeclMatches(
605 "struct Z {"
606 " void operator delete(void *);"
607 "};",
608 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000609 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000610 "void operator delete(void *) noexcept"));
611 // Should be: with semicolon, without noexcept?
612}
613
614TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
615 ASSERT_TRUE(PrintedDeclMatches(
616 "struct Z {"
617 " void operator delete(void *);"
618 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000619 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000620 "void operator delete(void *)"));
621 // Should be: with semicolon
622}
623
624TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
625 ASSERT_TRUE(PrintedDeclMatches(
626 "struct Z {"
627 " void operator delete[](void *);"
628 "};",
629 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000630 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000631 "void operator delete[](void *) noexcept"));
632 // Should be: with semicolon, without noexcept?
633}
634
635TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
636 const char *OperatorNames[] = {
637 "+", "-", "*", "/", "%", "^", "&", "|",
638 "=", "<", ">", "+=", "-=", "*=", "/=", "%=",
639 "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=",
640 "<=", ">=", "&&", "||", ",", "->*",
641 "()", "[]"
642 };
643
644 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
645 SmallString<128> Code;
646 Code.append("struct Z { void operator");
647 Code.append(OperatorNames[i]);
648 Code.append("(Z z); };");
649
650 SmallString<128> Expected;
651 Expected.append("void operator");
652 Expected.append(OperatorNames[i]);
653 Expected.append("(Z z)");
654 // Should be: with semicolon
655
656 ASSERT_TRUE(PrintedDeclMatches(
657 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000658 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000659 Expected));
660 }
661}
662
663TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
664 const char *OperatorNames[] = {
665 "~", "!", "++", "--", "->"
666 };
667
668 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
669 SmallString<128> Code;
670 Code.append("struct Z { void operator");
671 Code.append(OperatorNames[i]);
672 Code.append("(); };");
673
674 SmallString<128> Expected;
675 Expected.append("void operator");
676 Expected.append(OperatorNames[i]);
677 Expected.append("()");
678 // Should be: with semicolon
679
680 ASSERT_TRUE(PrintedDeclMatches(
681 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000682 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000683 Expected));
684 }
685}
686
687TEST(DeclPrinter, TestCXXMethodDecl1) {
688 ASSERT_TRUE(PrintedDeclMatches(
689 "struct Z {"
690 " void A(int a);"
691 "};",
692 "A",
693 "void A(int a)"));
694 // Should be: with semicolon
695}
696
697TEST(DeclPrinter, TestCXXMethodDecl2) {
698 ASSERT_TRUE(PrintedDeclMatches(
699 "struct Z {"
700 " virtual void A(int a);"
701 "};",
702 "A",
703 "virtual void A(int a)"));
704 // Should be: with semicolon
705}
706
707TEST(DeclPrinter, TestCXXMethodDecl3) {
708 ASSERT_TRUE(PrintedDeclMatches(
709 "struct Z {"
710 " virtual void A(int a);"
711 "};"
712 "struct ZZ : Z {"
713 " void A(int a);"
714 "};",
715 "ZZ::A",
716 "void A(int a)"));
717 // Should be: with semicolon
718 // TODO: should we print "virtual"?
719}
720
721TEST(DeclPrinter, TestCXXMethodDecl4) {
722 ASSERT_TRUE(PrintedDeclMatches(
723 "struct Z {"
724 " inline void A(int a);"
725 "};",
726 "A",
727 "inline void A(int a)"));
728 // Should be: with semicolon
729}
730
731TEST(DeclPrinter, TestCXXMethodDecl5) {
732 ASSERT_TRUE(PrintedDeclMatches(
733 "struct Z {"
734 " virtual void A(int a) = 0;"
735 "};",
736 "A",
737 "virtual void A(int a) = 0"));
738 // Should be: with semicolon
739}
740
741TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
742 ASSERT_TRUE(PrintedDeclMatches(
743 "struct Z {"
744 " void A(int a) const;"
745 "};",
746 "A",
747 "void A(int a) const"));
748 // Should be: with semicolon
749}
750
751TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
752 ASSERT_TRUE(PrintedDeclMatches(
753 "struct Z {"
754 " void A(int a) volatile;"
755 "};",
756 "A",
757 "void A(int a) volatile"));
758 // Should be: with semicolon
759}
760
761TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
762 ASSERT_TRUE(PrintedDeclMatches(
763 "struct Z {"
764 " void A(int a) const volatile;"
765 "};",
766 "A",
767 "void A(int a) const volatile"));
768 // Should be: with semicolon
769}
770
771TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
772 ASSERT_TRUE(PrintedDeclCXX11Matches(
773 "struct Z {"
774 " void A(int a) &;"
775 "};",
776 "A",
777 "void A(int a)"));
778 // WRONG; Should be: "void A(int a) &;"
779}
780
781TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
782 ASSERT_TRUE(PrintedDeclCXX11Matches(
783 "struct Z {"
784 " void A(int a) &&;"
785 "};",
786 "A",
787 "void A(int a)"));
788 // WRONG; Should be: "void A(int a) &&;"
789}
790
791TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
792 ASSERT_TRUE(PrintedDeclMatches(
793 "struct Z {"
794 " void A(int a) throw();"
795 "};",
796 "A",
797 "void A(int a) throw()"));
798 // Should be: with semicolon
799}
800
801TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
802 ASSERT_TRUE(PrintedDeclMatches(
803 "struct Z {"
804 " void A(int a) throw(int);"
805 "};",
806 "A",
807 "void A(int a) throw(int)"));
808 // Should be: with semicolon
809}
810
811TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
812 ASSERT_TRUE(PrintedDeclMatches(
813 "class ZZ {};"
814 "struct Z {"
815 " void A(int a) throw(ZZ, int);"
816 "};",
817 "A",
818 "void A(int a) throw(ZZ, int)"));
819 // Should be: with semicolon
820}
821
822TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
823 ASSERT_TRUE(PrintedDeclCXX11Matches(
824 "struct Z {"
825 " void A(int a) noexcept;"
826 "};",
827 "A",
828 "void A(int a) noexcept"));
829 // Should be: with semicolon
830}
831
832TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) {
833 ASSERT_TRUE(PrintedDeclCXX11Matches(
834 "struct Z {"
835 " void A(int a) noexcept(true);"
836 "};",
837 "A",
838 "void A(int a) noexcept(trueA(int a) noexcept(true)"));
839 // WRONG; Should be: "void A(int a) noexcept(true);"
840}
841
842TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
843 ASSERT_TRUE(PrintedDeclCXX11Matches(
844 "struct Z {"
845 " void A(int a) noexcept(1 < 2);"
846 "};",
847 "A",
848 "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
849 // WRONG; Should be: "void A(int a) noexcept(1 < 2);"
850}
851
852TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
853 ASSERT_TRUE(PrintedDeclCXX11Matches(
854 "template<int N>"
855 "struct Z {"
856 " void A(int a) noexcept(N < 2);"
857 "};",
858 "A",
859 "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
860 // WRONG; Should be: "void A(int a) noexcept(N < 2);"
861}
862
863TEST(DeclPrinter, TestVarDecl1) {
864 ASSERT_TRUE(PrintedDeclMatches(
865 "char *const (*(*A)[5])(int);",
866 "A",
867 "char *const (*(*A)[5])(int)"));
868 // Should be: with semicolon
869}
870
871TEST(DeclPrinter, TestVarDecl2) {
872 ASSERT_TRUE(PrintedDeclMatches(
873 "void (*A)() throw(int);",
874 "A",
875 "void (*A)() throw(int)"));
876 // Should be: with semicolon
877}
878
879TEST(DeclPrinter, TestVarDecl3) {
880 ASSERT_TRUE(PrintedDeclCXX11Matches(
881 "void (*A)() noexcept;",
882 "A",
883 "void (*A)() noexcept"));
884 // Should be: with semicolon
885}
886
887TEST(DeclPrinter, TestFieldDecl1) {
888 ASSERT_TRUE(PrintedDeclMatches(
889 "template<typename T>"
890 "struct Z { T A; };",
891 "A",
892 "T A"));
893 // Should be: with semicolon
894}
895
896TEST(DeclPrinter, TestFieldDecl2) {
897 ASSERT_TRUE(PrintedDeclMatches(
898 "template<int N>"
899 "struct Z { int A[N]; };",
900 "A",
901 "int A[N]"));
902 // Should be: with semicolon
903}
904
905TEST(DeclPrinter, TestClassTemplateDecl1) {
906 ASSERT_TRUE(PrintedDeclMatches(
907 "template<typename T>"
908 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000909 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000910 "template <typename T> struct A {\n}"));
911 // Should be: with semicolon, with { ... }
912}
913
914TEST(DeclPrinter, TestClassTemplateDecl2) {
915 ASSERT_TRUE(PrintedDeclMatches(
916 "template<typename T = int>"
917 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000918 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000919 "template <typename T = int> struct A {\n}"));
920 // Should be: with semicolon, with { ... }
921}
922
923TEST(DeclPrinter, TestClassTemplateDecl3) {
924 ASSERT_TRUE(PrintedDeclMatches(
925 "template<class T>"
926 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000927 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000928 "template <class T> struct A {\n}"));
929 // Should be: with semicolon, with { ... }
930}
931
932TEST(DeclPrinter, TestClassTemplateDecl4) {
933 ASSERT_TRUE(PrintedDeclMatches(
934 "template<typename T, typename U>"
935 "struct A { T a; U b; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000936 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000937 "template <typename T, typename U> struct A {\n}"));
938 // Should be: with semicolon, with { ... }
939}
940
941TEST(DeclPrinter, TestClassTemplateDecl5) {
942 ASSERT_TRUE(PrintedDeclMatches(
943 "template<int N>"
944 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000945 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000946 "template <int N> struct A {\n}"));
947 // Should be: with semicolon, with { ... }
948}
949
950TEST(DeclPrinter, TestClassTemplateDecl6) {
951 ASSERT_TRUE(PrintedDeclMatches(
952 "template<int N = 42>"
953 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000954 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000955 "template <int N = 42> struct A {\n}"));
956 // Should be: with semicolon, with { ... }
957}
958
959TEST(DeclPrinter, TestClassTemplateDecl7) {
960 ASSERT_TRUE(PrintedDeclMatches(
961 "typedef int MyInt;"
962 "template<MyInt N>"
963 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000964 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000965 "template <MyInt N> struct A {\n}"));
966 // Should be: with semicolon, with { ... }
967}
968
969TEST(DeclPrinter, TestClassTemplateDecl8) {
970 ASSERT_TRUE(PrintedDeclMatches(
971 "template<template<typename U> class T> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000972 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000973 "template <template <typename U> class T> struct A {\n}"));
974 // Should be: with semicolon, with { ... }
975}
976
977TEST(DeclPrinter, TestClassTemplateDecl9) {
978 ASSERT_TRUE(PrintedDeclMatches(
979 "template<typename T> struct Z { };"
980 "template<template<typename U> class T = Z> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000981 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000982 "template <template <typename U> class T> struct A {\n}"));
983 // Should be: with semicolon, with { ... }
984}
985
986TEST(DeclPrinter, TestClassTemplateDecl10) {
987 ASSERT_TRUE(PrintedDeclCXX11Matches(
988 "template<typename... T>"
989 "struct A { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000990 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000991 "template <typename ... T> struct A {\n}"));
992 // Should be: with semicolon, with { ... }, without spaces before '...'
993}
994
995TEST(DeclPrinter, TestClassTemplateDecl11) {
996 ASSERT_TRUE(PrintedDeclCXX11Matches(
997 "template<typename... T>"
998 "struct A : public T... { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000999 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001000 "template <typename ... T> struct A : public T... {\n}"));
1001 // Should be: with semicolon, with { ... }, without spaces before '...'
1002}
1003
1004TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
1005 ASSERT_TRUE(PrintedDeclMatches(
1006 "template<typename T, typename U>"
1007 "struct A { T a; U b; };"
1008 "template<typename T>"
1009 "struct A<T, int> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001010 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001011 "struct A {\n}"));
1012 // WRONG; Should be: "template<typename T> struct A<T, int> { ... }"
1013}
1014
1015TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
1016 ASSERT_TRUE(PrintedDeclMatches(
1017 "template<typename T>"
1018 "struct A { T a; };"
1019 "template<typename T>"
1020 "struct A<T *> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001021 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001022 "struct A {\n}"));
1023 // WRONG; Should be: "template<typename T> struct A<T *> { ... }"
1024}
1025
1026TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
1027 ASSERT_TRUE(PrintedDeclMatches(
1028 "template<typename T>"
1029 "struct A { T a; };"
1030 "template<>"
1031 "struct A<int> { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001032 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001033 "struct A {\n}"));
1034 // WRONG; Should be: "template<> struct A<int> { ... }"
1035}
1036
1037TEST(DeclPrinter, TestFunctionTemplateDecl1) {
1038 ASSERT_TRUE(PrintedDeclMatches(
1039 "template<typename T>"
1040 "void A(T &t);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001041 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001042 "template <typename T> void A(T &t)"));
1043 // Should be: with semicolon
1044}
1045
1046TEST(DeclPrinter, TestFunctionTemplateDecl2) {
1047 ASSERT_TRUE(PrintedDeclMatches(
1048 "template<typename T>"
1049 "void A(T &t) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001050 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001051 "template <typename T> void A(T &t)"));
1052 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001053}
1054
1055TEST(DeclPrinter, TestFunctionTemplateDecl3) {
1056 ASSERT_TRUE(PrintedDeclCXX11Matches(
1057 "template<typename... T>"
1058 "void A(T... a);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001059 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001060 "template <typename ... T> void A(T a...)"));
1061 // WRONG; Should be: "template <typename ... T> void A(T... a)"
1062 // (not "T a...")
1063 // Should be: with semicolon.
1064}
1065
1066TEST(DeclPrinter, TestFunctionTemplateDecl4) {
1067 ASSERT_TRUE(PrintedDeclMatches(
1068 "struct Z { template<typename T> void A(T t); };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001069 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001070 "template <typename T> void A(T t)"));
1071 // Should be: with semicolon
1072}
1073
1074TEST(DeclPrinter, TestFunctionTemplateDecl5) {
1075 ASSERT_TRUE(PrintedDeclMatches(
1076 "struct Z { template<typename T> void A(T t) {} };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001077 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001078 "template <typename T> void A(T t)"));
1079 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001080}
1081
1082TEST(DeclPrinter, TestFunctionTemplateDecl6) {
1083 ASSERT_TRUE(PrintedDeclMatches(
1084 "template<typename T >struct Z {"
1085 " template<typename U> void A(U t) {}"
1086 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001087 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001088 "template <typename U> void A(U t)"));
1089 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001090}
1091
1092TEST(DeclPrinter, TestTemplateArgumentList1) {
1093 ASSERT_TRUE(PrintedDeclMatches(
1094 "template<typename T> struct Z {};"
1095 "struct X {};"
1096 "Z<X> A;",
1097 "A",
1098 "Z<X> A"));
1099 // Should be: with semicolon
1100}
1101
1102TEST(DeclPrinter, TestTemplateArgumentList2) {
1103 ASSERT_TRUE(PrintedDeclMatches(
1104 "template<typename T, typename U> struct Z {};"
1105 "struct X {};"
1106 "typedef int Y;"
1107 "Z<X, Y> A;",
1108 "A",
1109 "Z<X, Y> A"));
1110 // Should be: with semicolon
1111}
1112
1113TEST(DeclPrinter, TestTemplateArgumentList3) {
1114 ASSERT_TRUE(PrintedDeclMatches(
1115 "template<typename T> struct Z {};"
1116 "template<typename T> struct X {};"
1117 "Z<X<int> > A;",
1118 "A",
1119 "Z<X<int> > A"));
1120 // Should be: with semicolon
1121}
1122
1123TEST(DeclPrinter, TestTemplateArgumentList4) {
1124 ASSERT_TRUE(PrintedDeclCXX11Matches(
1125 "template<typename T> struct Z {};"
1126 "template<typename T> struct X {};"
1127 "Z<X<int>> A;",
1128 "A",
1129 "Z<X<int> > A"));
1130 // Should be: with semicolon, without extra space in "> >"
1131}
1132
1133TEST(DeclPrinter, TestTemplateArgumentList5) {
1134 ASSERT_TRUE(PrintedDeclCXX11Matches(
1135 "template<typename T> struct Z {};"
1136 "template<typename T> struct X { Z<T> A; };",
1137 "A",
1138 "Z<T> A"));
1139 // Should be: with semicolon
1140}
1141
1142TEST(DeclPrinter, TestTemplateArgumentList6) {
1143 ASSERT_TRUE(PrintedDeclMatches(
1144 "template<template<typename T> class U> struct Z {};"
1145 "template<typename T> struct X {};"
1146 "Z<X> A;",
1147 "A",
1148 "Z<X> A"));
1149 // Should be: with semicolon
1150}
1151
1152TEST(DeclPrinter, TestTemplateArgumentList7) {
1153 ASSERT_TRUE(PrintedDeclCXX11Matches(
1154 "template<template<typename T> class U> struct Z {};"
1155 "template<template<typename T> class U> struct Y {"
1156 " Z<U> A;"
1157 "};",
1158 "A",
1159 "Z<U> A"));
1160 // Should be: with semicolon
1161}
1162
1163TEST(DeclPrinter, TestTemplateArgumentList8) {
1164 ASSERT_TRUE(PrintedDeclCXX11Matches(
1165 "template<typename T> struct Z {};"
1166 "template<template<typename T> class U> struct Y {"
1167 " Z<U<int> > A;"
1168 "};",
1169 "A",
1170 "Z<U<int> > A"));
1171 // Should be: with semicolon
1172}
1173
1174TEST(DeclPrinter, TestTemplateArgumentList9) {
1175 ASSERT_TRUE(PrintedDeclMatches(
1176 "template<unsigned I> struct Z {};"
1177 "Z<0> A;",
1178 "A",
1179 "Z<0> A"));
1180 // Should be: with semicolon
1181}
1182
1183TEST(DeclPrinter, TestTemplateArgumentList10) {
1184 ASSERT_TRUE(PrintedDeclMatches(
1185 "template<unsigned I> struct Z {};"
1186 "template<unsigned I> struct X { Z<I> A; };",
1187 "A",
1188 "Z<I> A"));
1189 // Should be: with semicolon
1190}
1191
1192TEST(DeclPrinter, TestTemplateArgumentList11) {
1193 ASSERT_TRUE(PrintedDeclMatches(
1194 "template<int I> struct Z {};"
1195 "Z<42 * 10 - 420 / 1> A;",
1196 "A",
1197 "Z<42 * 10 - 420 / 1> A"));
1198 // Should be: with semicolon
1199}
1200
1201TEST(DeclPrinter, TestTemplateArgumentList12) {
1202 ASSERT_TRUE(PrintedDeclMatches(
1203 "template<const char *p> struct Z {};"
1204 "extern const char X[] = \"aaa\";"
1205 "Z<X> A;",
1206 "A",
1207 "Z<X> A"));
1208 // Should be: with semicolon
1209}
1210
1211TEST(DeclPrinter, TestTemplateArgumentList13) {
1212 ASSERT_TRUE(PrintedDeclCXX11Matches(
1213 "template<typename... T> struct Z {};"
1214 "template<typename... T> struct X {"
1215 " Z<T...> A;"
1216 "};",
1217 "A",
1218 "Z<T...> A"));
1219 // Should be: with semicolon, without extra space in "> >"
1220}
1221
1222TEST(DeclPrinter, TestTemplateArgumentList14) {
1223 ASSERT_TRUE(PrintedDeclCXX11Matches(
1224 "template<typename... T> struct Z {};"
1225 "template<typename T> struct Y {};"
1226 "template<typename... T> struct X {"
1227 " Z<Y<T>...> A;"
1228 "};",
1229 "A",
1230 "Z<Y<T>...> A"));
1231 // Should be: with semicolon, without extra space in "> >"
1232}
1233
1234TEST(DeclPrinter, TestTemplateArgumentList15) {
1235 ASSERT_TRUE(PrintedDeclCXX11Matches(
1236 "template<unsigned I> struct Z {};"
1237 "template<typename... T> struct X {"
1238 " Z<sizeof...(T)> A;"
1239 "};",
1240 "A",
1241 "Z<sizeof...(T)> A"));
1242 // Should be: with semicolon, without extra space in "> >"
1243}