blob: 332018e384a229a188f0508fdfc15189b2a57dc5 [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");
76 ArgVector.push_back(FileNameRef.data());
77 for (unsigned i = 0, e = ClangArgs.size(); i != e; ++i)
78 ArgVector.push_back(ClangArgs[i]);
79
80 FileManager Files((FileSystemOptions()));
81 ToolInvocation Invocation(ArgVector, ToolAction, &Files);
82
83 SmallString<1024> CodeStorage;
84 Invocation.mapVirtualFile(FileNameRef,
85 Code.toNullTerminatedStringRef(CodeStorage));
86 return Invocation.run();
87}
88
89::testing::AssertionResult PrintedDeclMatches(
90 StringRef Code,
91 ArrayRef<const char *> ClangArgs,
92 const DeclarationMatcher &NodeMatch,
93 StringRef ExpectedPrinted) {
94 PrintMatch Printer;
95 MatchFinder Finder;
96 Finder.addMatcher(NodeMatch, &Printer);
97 OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder));
98
99 if (!runToolOnCode(Factory->create(), Code, ClangArgs))
100 return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
101
102 if (Printer.getNumFoundDecls() == 0)
103 return testing::AssertionFailure()
104 << "Matcher didn't find any declarations";
105
106 if (Printer.getNumFoundDecls() > 1)
107 return testing::AssertionFailure()
108 << "Matcher should match only one declaration "
109 "(found " << Printer.getNumFoundDecls() << ")";
110
111 if (Printer.getPrinted() != ExpectedPrinted)
112 return ::testing::AssertionFailure()
113 << "Expected \"" << ExpectedPrinted << "\", "
114 "got \"" << Printer.getPrinted() << "\"";
115
116 return ::testing::AssertionSuccess();
117}
118
119::testing::AssertionResult PrintedDeclMatches(StringRef Code,
120 StringRef DeclName,
121 StringRef ExpectedPrinted) {
122 return PrintedDeclMatches(Code,
123 ArrayRef<const char *>(),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000124 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000125 ExpectedPrinted);
126}
127
128::testing::AssertionResult PrintedDeclMatches(
129 StringRef Code,
130 const DeclarationMatcher &NodeMatch,
131 StringRef ExpectedPrinted) {
132 return PrintedDeclMatches(Code,
133 ArrayRef<const char *>(),
134 NodeMatch,
135 ExpectedPrinted);
136}
137
138::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
139 StringRef DeclName,
140 StringRef ExpectedPrinted) {
141 return PrintedDeclMatches(Code,
142 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000143 namedDecl(hasName(DeclName)).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000144 ExpectedPrinted);
145}
146
147::testing::AssertionResult PrintedDeclCXX11Matches(
148 StringRef Code,
149 const DeclarationMatcher &NodeMatch,
150 StringRef ExpectedPrinted) {
151 return PrintedDeclMatches(Code,
152 ArrayRef<const char *>("-std=c++11"),
153 NodeMatch,
154 ExpectedPrinted);
155}
156
157} // unnamed namespace
158
159TEST(DeclPrinter, TestNamespace1) {
160 ASSERT_TRUE(PrintedDeclMatches(
161 "namespace A { int B; }",
162 "A",
163 "namespace A {\n}"));
164 // Should be: with { ... }
165}
166
167TEST(DeclPrinter, TestNamespace2) {
168 ASSERT_TRUE(PrintedDeclCXX11Matches(
169 "inline namespace A { int B; }",
170 "A",
171 "inline namespace A {\n}"));
172 // Should be: with { ... }
173}
174
175TEST(DeclPrinter, TestNamespaceAlias1) {
176 ASSERT_TRUE(PrintedDeclMatches(
177 "namespace Z { }"
178 "namespace A = Z;",
179 "A",
180 "namespace A = Z"));
181 // Should be: with semicolon
182}
183
184TEST(DeclPrinter, TestNamespaceAlias2) {
185 ASSERT_TRUE(PrintedDeclMatches(
186 "namespace X { namespace Y {} }"
187 "namespace A = X::Y;",
188 "A",
189 "namespace A = X::Y"));
190 // Should be: with semicolon
191}
192
193TEST(DeclPrinter, TestCXXRecordDecl1) {
194 ASSERT_TRUE(PrintedDeclMatches(
195 "class A { int a; };",
196 "A",
197 "class A {\n}"));
198 // Should be: with semicolon, with { ... }
199}
200
201TEST(DeclPrinter, TestCXXRecordDecl2) {
202 ASSERT_TRUE(PrintedDeclMatches(
203 "struct A { int a; };",
204 "A",
205 "struct A {\n}"));
206 // Should be: with semicolon, with { ... }
207}
208
209TEST(DeclPrinter, TestCXXRecordDecl3) {
210 ASSERT_TRUE(PrintedDeclMatches(
211 "union A { int a; };",
212 "A",
213 "union A {\n}"));
214 // Should be: with semicolon, with { ... }
215}
216
217TEST(DeclPrinter, TestCXXRecordDecl4) {
218 ASSERT_TRUE(PrintedDeclMatches(
219 "class Z { int a; };"
220 "class A : Z { int b; };",
221 "A",
222 "class A : Z {\n}"));
223 // Should be: with semicolon, with { ... }, without two spaces
224}
225
226TEST(DeclPrinter, TestCXXRecordDecl5) {
227 ASSERT_TRUE(PrintedDeclMatches(
228 "struct Z { int a; };"
229 "struct A : Z { int b; };",
230 "A",
231 "struct A : Z {\n}"));
232 // Should be: with semicolon, with { ... }, without two spaces
233}
234
235TEST(DeclPrinter, TestCXXRecordDecl6) {
236 ASSERT_TRUE(PrintedDeclMatches(
237 "class Z { int a; };"
238 "class A : public Z { int b; };",
239 "A",
240 "class A : public Z {\n}"));
241 // Should be: with semicolon, with { ... }
242}
243
244TEST(DeclPrinter, TestCXXRecordDecl7) {
245 ASSERT_TRUE(PrintedDeclMatches(
246 "class Z { int a; };"
247 "class A : protected Z { int b; };",
248 "A",
249 "class A : protected Z {\n}"));
250 // Should be: with semicolon, with { ... }
251}
252
253TEST(DeclPrinter, TestCXXRecordDecl8) {
254 ASSERT_TRUE(PrintedDeclMatches(
255 "class Z { int a; };"
256 "class A : private Z { int b; };",
257 "A",
258 "class A : private Z {\n}"));
259 // Should be: with semicolon, with { ... }
260}
261
262TEST(DeclPrinter, TestCXXRecordDecl9) {
263 ASSERT_TRUE(PrintedDeclMatches(
264 "class Z { int a; };"
265 "class A : virtual Z { int b; };",
266 "A",
267 "class A : virtual Z {\n}"));
268 // Should be: with semicolon, with { ... }, without two spaces
269}
270
271TEST(DeclPrinter, TestCXXRecordDecl10) {
272 ASSERT_TRUE(PrintedDeclMatches(
273 "class Z { int a; };"
274 "class A : virtual public Z { int b; };",
275 "A",
276 "class A : virtual public Z {\n}"));
277 // Should be: with semicolon, with { ... }
278}
279
280TEST(DeclPrinter, TestCXXRecordDecl11) {
281 ASSERT_TRUE(PrintedDeclMatches(
282 "class Z { int a; };"
283 "class Y : virtual public Z { int b; };"
284 "class A : virtual public Z, private Y { int c; };",
285 "A",
286 "class A : virtual public Z, private Y {\n}"));
287 // Should be: with semicolon, with { ... }
288}
289
290TEST(DeclPrinter, TestFunctionDecl1) {
291 ASSERT_TRUE(PrintedDeclMatches(
292 "void A();",
293 "A",
294 "void A()"));
295 // Should be: with semicolon
296}
297
298TEST(DeclPrinter, TestFunctionDecl2) {
299 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000300 "void A() {}",
301 "A",
302 "void A()"));
303 // Should be: with semicolon
304}
305
306TEST(DeclPrinter, TestFunctionDecl3) {
307 ASSERT_TRUE(PrintedDeclMatches(
308 "void Z();"
309 "void A() { Z(); }",
310 "A",
311 "void A()"));
312 // Should be: with semicolon
313}
314
315TEST(DeclPrinter, TestFunctionDecl4) {
316 ASSERT_TRUE(PrintedDeclMatches(
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000317 "extern void A();",
318 "A",
319 "extern void A()"));
320 // Should be: with semicolon
321}
322
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000323TEST(DeclPrinter, TestFunctionDecl5) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000324 ASSERT_TRUE(PrintedDeclMatches(
325 "static void A();",
326 "A",
327 "static void A()"));
328 // Should be: with semicolon
329}
330
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000331TEST(DeclPrinter, TestFunctionDecl6) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000332 ASSERT_TRUE(PrintedDeclMatches(
333 "inline void A();",
334 "A",
335 "inline void A()"));
336 // Should be: with semicolon
337}
338
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000339TEST(DeclPrinter, TestFunctionDecl7) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000340 ASSERT_TRUE(PrintedDeclCXX11Matches(
341 "constexpr int A(int a);",
342 "A",
343 "int A(int a)"));
344 // WRONG; Should be: "constexpr int A(int a);"
345}
346
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000347TEST(DeclPrinter, TestFunctionDecl8) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000348 ASSERT_TRUE(PrintedDeclMatches(
349 "void A(int a);",
350 "A",
351 "void A(int a)"));
352 // Should be: with semicolon
353}
354
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000355TEST(DeclPrinter, TestFunctionDecl9) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000356 ASSERT_TRUE(PrintedDeclMatches(
357 "void A(...);",
358 "A",
359 "void A(...)"));
360 // Should be: with semicolon
361}
362
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000363TEST(DeclPrinter, TestFunctionDecl10) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000364 ASSERT_TRUE(PrintedDeclMatches(
365 "void A(int a, ...);",
366 "A",
367 "void A(int a, ...)"));
368 // Should be: with semicolon
369}
370
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000371TEST(DeclPrinter, TestFunctionDecl11) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000372 ASSERT_TRUE(PrintedDeclMatches(
373 "typedef long size_t;"
374 "typedef int *pInt;"
375 "void A(int a, pInt b, size_t c);",
376 "A",
377 "void A(int a, pInt b, size_t c)"));
378 // Should be: with semicolon
379}
380
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000381TEST(DeclPrinter, TestFunctionDecl12) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000382 ASSERT_TRUE(PrintedDeclMatches(
383 "void A(int a, int b = 0);",
384 "A",
385 "void A(int a, int b = 0)"));
386 // Should be: with semicolon
387}
388
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000389TEST(DeclPrinter, TestFunctionDecl13) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000390 ASSERT_TRUE(PrintedDeclMatches(
391 "void (*A(int a))(int b);",
392 "A",
393 "void (*A(int a))(int)"));
394 // Should be: with semicolon, with parameter name (?)
395}
396
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000397TEST(DeclPrinter, TestFunctionDecl14) {
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000398 ASSERT_TRUE(PrintedDeclMatches(
399 "template<typename T>"
400 "void A(T t) { }"
401 "template<>"
402 "void A(int N) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000403 functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +0000404 "void A(int N)"));
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000405 // WRONG; Should be: "template <> void A(int N);"));
406}
407
408
409TEST(DeclPrinter, TestCXXConstructorDecl1) {
410 ASSERT_TRUE(PrintedDeclMatches(
411 "struct A {"
412 " A();"
413 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000414 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000415 ""));
416 // WRONG; Should be: "A();"
417}
418
419TEST(DeclPrinter, TestCXXConstructorDecl2) {
420 ASSERT_TRUE(PrintedDeclMatches(
421 "struct A {"
422 " A(int a);"
423 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000424 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000425 ""));
426 // WRONG; Should be: "A(int a);"
427}
428
429TEST(DeclPrinter, TestCXXConstructorDecl3) {
430 ASSERT_TRUE(PrintedDeclMatches(
431 "struct A {"
432 " A(const A &a);"
433 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000434 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000435 ""));
436 // WRONG; Should be: "A(const A &a);"
437}
438
439TEST(DeclPrinter, TestCXXConstructorDecl4) {
440 ASSERT_TRUE(PrintedDeclMatches(
441 "struct A {"
442 " A(const A &a, int = 0);"
443 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000444 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000445 ""));
446 // WRONG; Should be: "A(const A &a, int = 0);"
447}
448
449TEST(DeclPrinter, TestCXXConstructorDecl5) {
450 ASSERT_TRUE(PrintedDeclCXX11Matches(
451 "struct A {"
452 " A(const A &&a);"
453 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000454 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000455 ""));
456 // WRONG; Should be: "A(const A &&a);"
457}
458
459TEST(DeclPrinter, TestCXXConstructorDecl6) {
460 ASSERT_TRUE(PrintedDeclMatches(
461 "struct A {"
462 " explicit A(int a);"
463 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000464 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000465 ""));
466 // WRONG; Should be: "explicit A(int a);"
467}
468
469TEST(DeclPrinter, TestCXXConstructorDecl7) {
470 ASSERT_TRUE(PrintedDeclMatches(
471 "struct A {"
472 " constexpr A();"
473 "};",
474 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000475 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000476 ""));
477 // WRONG; Should be: "constexpr A();"
478}
479
480TEST(DeclPrinter, TestCXXConstructorDecl8) {
481 ASSERT_TRUE(PrintedDeclMatches(
482 "struct A {"
483 " A() = default;"
484 "};",
485 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000486 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000487 ""));
488 // WRONG; Should be: "A() = default;"
489}
490
491TEST(DeclPrinter, TestCXXConstructorDecl9) {
492 ASSERT_TRUE(PrintedDeclMatches(
493 "struct A {"
494 " A() = delete;"
495 "};",
496 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000497 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000498 " = delete"));
499 // WRONG; Should be: "A() = delete;"
500}
501
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000502TEST(DeclPrinter, TestCXXConstructorDecl10) {
503 ASSERT_TRUE(PrintedDeclCXX11Matches(
504 "template<typename... T>"
505 "struct A {"
506 " A(const A &a);"
507 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000508 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000509 ""));
510 // WRONG; Should be: "A(const A &a);"
511}
512
513TEST(DeclPrinter, TestCXXConstructorDecl11) {
514 ASSERT_TRUE(PrintedDeclCXX11Matches(
515 "template<typename... T>"
516 "struct A : public T... {"
517 " A(T&&... ts) : T(ts)... {}"
518 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000519 constructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000520 "A<T...>(T &&ts...) : T(ts)"));
Dmitri Gribenkof6ec15a2012-08-24 00:27:50 +0000521 // WRONG; Should be: "A(T&&... ts) : T(ts)..."
Dmitri Gribenkoc4684242012-08-24 00:26:25 +0000522}
523
524
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000525TEST(DeclPrinter, TestCXXDestructorDecl1) {
526 ASSERT_TRUE(PrintedDeclMatches(
527 "struct A {"
528 " ~A();"
529 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000530 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000531 "void ~A()"));
532 // WRONG; Should be: "~A();"
533}
534
535TEST(DeclPrinter, TestCXXDestructorDecl2) {
536 ASSERT_TRUE(PrintedDeclMatches(
537 "struct A {"
538 " virtual ~A();"
539 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000540 destructorDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000541 "virtual void ~A()"));
542 // WRONG; Should be: "virtual ~A();"
543}
544
545TEST(DeclPrinter, TestCXXConversionDecl1) {
546 ASSERT_TRUE(PrintedDeclMatches(
547 "struct A {"
548 " operator int();"
549 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000550 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000551 "int operator int()"));
552 // WRONG; Should be: "operator int();"
553}
554
555TEST(DeclPrinter, TestCXXConversionDecl2) {
556 ASSERT_TRUE(PrintedDeclMatches(
557 "struct A {"
558 " operator bool();"
559 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000560 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000561 "bool operator _Bool()"));
562 // WRONG; Should be: "operator bool();"
563}
564
565TEST(DeclPrinter, TestCXXConversionDecl3) {
566 ASSERT_TRUE(PrintedDeclMatches(
567 "struct Z {};"
568 "struct A {"
569 " operator Z();"
570 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000571 methodDecl(ofClass(hasName("A"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000572 "Z operator struct Z()"));
573 // WRONG; Should be: "operator Z();"
574}
575
576TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
577 ASSERT_TRUE(PrintedDeclMatches(
578 "namespace std { typedef decltype(sizeof(int)) size_t; }"
579 "struct Z {"
580 " void *operator new(std::size_t);"
581 "};",
582 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000583 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000584 "void *operator new(std::size_t)"));
585 // Should be: with semicolon
586}
587
588TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
589 ASSERT_TRUE(PrintedDeclMatches(
590 "namespace std { typedef decltype(sizeof(int)) size_t; }"
591 "struct Z {"
592 " void *operator new[](std::size_t);"
593 "};",
594 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000595 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000596 "void *operator new[](std::size_t)"));
597 // Should be: with semicolon
598}
599
600TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
601 ASSERT_TRUE(PrintedDeclMatches(
602 "struct Z {"
603 " void operator delete(void *);"
604 "};",
605 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000606 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000607 "void operator delete(void *) noexcept"));
608 // Should be: with semicolon, without noexcept?
609}
610
611TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
612 ASSERT_TRUE(PrintedDeclMatches(
613 "struct Z {"
614 " void operator delete(void *);"
615 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000616 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000617 "void operator delete(void *)"));
618 // Should be: with semicolon
619}
620
621TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
622 ASSERT_TRUE(PrintedDeclMatches(
623 "struct Z {"
624 " void operator delete[](void *);"
625 "};",
626 ArrayRef<const char *>("-std=c++11"),
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000627 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000628 "void operator delete[](void *) noexcept"));
629 // Should be: with semicolon, without noexcept?
630}
631
632TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
633 const char *OperatorNames[] = {
634 "+", "-", "*", "/", "%", "^", "&", "|",
635 "=", "<", ">", "+=", "-=", "*=", "/=", "%=",
636 "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=",
637 "<=", ">=", "&&", "||", ",", "->*",
638 "()", "[]"
639 };
640
641 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
642 SmallString<128> Code;
643 Code.append("struct Z { void operator");
644 Code.append(OperatorNames[i]);
645 Code.append("(Z z); };");
646
647 SmallString<128> Expected;
648 Expected.append("void operator");
649 Expected.append(OperatorNames[i]);
650 Expected.append("(Z z)");
651 // Should be: with semicolon
652
653 ASSERT_TRUE(PrintedDeclMatches(
654 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000655 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000656 Expected));
657 }
658}
659
660TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
661 const char *OperatorNames[] = {
662 "~", "!", "++", "--", "->"
663 };
664
665 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
666 SmallString<128> Code;
667 Code.append("struct Z { void operator");
668 Code.append(OperatorNames[i]);
669 Code.append("(); };");
670
671 SmallString<128> Expected;
672 Expected.append("void operator");
673 Expected.append(OperatorNames[i]);
674 Expected.append("()");
675 // Should be: with semicolon
676
677 ASSERT_TRUE(PrintedDeclMatches(
678 Code,
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000679 methodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000680 Expected));
681 }
682}
683
684TEST(DeclPrinter, TestCXXMethodDecl1) {
685 ASSERT_TRUE(PrintedDeclMatches(
686 "struct Z {"
687 " void A(int a);"
688 "};",
689 "A",
690 "void A(int a)"));
691 // Should be: with semicolon
692}
693
694TEST(DeclPrinter, TestCXXMethodDecl2) {
695 ASSERT_TRUE(PrintedDeclMatches(
696 "struct Z {"
697 " virtual void A(int a);"
698 "};",
699 "A",
700 "virtual void A(int a)"));
701 // Should be: with semicolon
702}
703
704TEST(DeclPrinter, TestCXXMethodDecl3) {
705 ASSERT_TRUE(PrintedDeclMatches(
706 "struct Z {"
707 " virtual void A(int a);"
708 "};"
709 "struct ZZ : Z {"
710 " void A(int a);"
711 "};",
712 "ZZ::A",
713 "void A(int a)"));
714 // Should be: with semicolon
715 // TODO: should we print "virtual"?
716}
717
718TEST(DeclPrinter, TestCXXMethodDecl4) {
719 ASSERT_TRUE(PrintedDeclMatches(
720 "struct Z {"
721 " inline void A(int a);"
722 "};",
723 "A",
724 "inline void A(int a)"));
725 // Should be: with semicolon
726}
727
728TEST(DeclPrinter, TestCXXMethodDecl5) {
729 ASSERT_TRUE(PrintedDeclMatches(
730 "struct Z {"
731 " virtual void A(int a) = 0;"
732 "};",
733 "A",
734 "virtual void A(int a) = 0"));
735 // Should be: with semicolon
736}
737
738TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
739 ASSERT_TRUE(PrintedDeclMatches(
740 "struct Z {"
741 " void A(int a) const;"
742 "};",
743 "A",
744 "void A(int a) const"));
745 // Should be: with semicolon
746}
747
748TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
749 ASSERT_TRUE(PrintedDeclMatches(
750 "struct Z {"
751 " void A(int a) volatile;"
752 "};",
753 "A",
754 "void A(int a) volatile"));
755 // Should be: with semicolon
756}
757
758TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
759 ASSERT_TRUE(PrintedDeclMatches(
760 "struct Z {"
761 " void A(int a) const volatile;"
762 "};",
763 "A",
764 "void A(int a) const volatile"));
765 // Should be: with semicolon
766}
767
768TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
769 ASSERT_TRUE(PrintedDeclCXX11Matches(
770 "struct Z {"
771 " void A(int a) &;"
772 "};",
773 "A",
774 "void A(int a)"));
775 // WRONG; Should be: "void A(int a) &;"
776}
777
778TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
779 ASSERT_TRUE(PrintedDeclCXX11Matches(
780 "struct Z {"
781 " void A(int a) &&;"
782 "};",
783 "A",
784 "void A(int a)"));
785 // WRONG; Should be: "void A(int a) &&;"
786}
787
788TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
789 ASSERT_TRUE(PrintedDeclMatches(
790 "struct Z {"
791 " void A(int a) throw();"
792 "};",
793 "A",
794 "void A(int a) throw()"));
795 // Should be: with semicolon
796}
797
798TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
799 ASSERT_TRUE(PrintedDeclMatches(
800 "struct Z {"
801 " void A(int a) throw(int);"
802 "};",
803 "A",
804 "void A(int a) throw(int)"));
805 // Should be: with semicolon
806}
807
808TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
809 ASSERT_TRUE(PrintedDeclMatches(
810 "class ZZ {};"
811 "struct Z {"
812 " void A(int a) throw(ZZ, int);"
813 "};",
814 "A",
815 "void A(int a) throw(ZZ, int)"));
816 // Should be: with semicolon
817}
818
819TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
820 ASSERT_TRUE(PrintedDeclCXX11Matches(
821 "struct Z {"
822 " void A(int a) noexcept;"
823 "};",
824 "A",
825 "void A(int a) noexcept"));
826 // Should be: with semicolon
827}
828
829TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) {
830 ASSERT_TRUE(PrintedDeclCXX11Matches(
831 "struct Z {"
832 " void A(int a) noexcept(true);"
833 "};",
834 "A",
835 "void A(int a) noexcept(trueA(int a) noexcept(true)"));
836 // WRONG; Should be: "void A(int a) noexcept(true);"
837}
838
839TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
840 ASSERT_TRUE(PrintedDeclCXX11Matches(
841 "struct Z {"
842 " void A(int a) noexcept(1 < 2);"
843 "};",
844 "A",
845 "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
846 // WRONG; Should be: "void A(int a) noexcept(1 < 2);"
847}
848
849TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
850 ASSERT_TRUE(PrintedDeclCXX11Matches(
851 "template<int N>"
852 "struct Z {"
853 " void A(int a) noexcept(N < 2);"
854 "};",
855 "A",
856 "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
857 // WRONG; Should be: "void A(int a) noexcept(N < 2);"
858}
859
860TEST(DeclPrinter, TestVarDecl1) {
861 ASSERT_TRUE(PrintedDeclMatches(
862 "char *const (*(*A)[5])(int);",
863 "A",
864 "char *const (*(*A)[5])(int)"));
865 // Should be: with semicolon
866}
867
868TEST(DeclPrinter, TestVarDecl2) {
869 ASSERT_TRUE(PrintedDeclMatches(
870 "void (*A)() throw(int);",
871 "A",
872 "void (*A)() throw(int)"));
873 // Should be: with semicolon
874}
875
876TEST(DeclPrinter, TestVarDecl3) {
877 ASSERT_TRUE(PrintedDeclCXX11Matches(
878 "void (*A)() noexcept;",
879 "A",
880 "void (*A)() noexcept"));
881 // Should be: with semicolon
882}
883
884TEST(DeclPrinter, TestFieldDecl1) {
885 ASSERT_TRUE(PrintedDeclMatches(
886 "template<typename T>"
887 "struct Z { T A; };",
888 "A",
889 "T A"));
890 // Should be: with semicolon
891}
892
893TEST(DeclPrinter, TestFieldDecl2) {
894 ASSERT_TRUE(PrintedDeclMatches(
895 "template<int N>"
896 "struct Z { int A[N]; };",
897 "A",
898 "int A[N]"));
899 // Should be: with semicolon
900}
901
902TEST(DeclPrinter, TestClassTemplateDecl1) {
903 ASSERT_TRUE(PrintedDeclMatches(
904 "template<typename T>"
905 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000906 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000907 "template <typename T> struct A {\n}"));
908 // Should be: with semicolon, with { ... }
909}
910
911TEST(DeclPrinter, TestClassTemplateDecl2) {
912 ASSERT_TRUE(PrintedDeclMatches(
913 "template<typename T = int>"
914 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000915 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000916 "template <typename T = int> struct A {\n}"));
917 // Should be: with semicolon, with { ... }
918}
919
920TEST(DeclPrinter, TestClassTemplateDecl3) {
921 ASSERT_TRUE(PrintedDeclMatches(
922 "template<class T>"
923 "struct A { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000924 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000925 "template <class T> struct A {\n}"));
926 // Should be: with semicolon, with { ... }
927}
928
929TEST(DeclPrinter, TestClassTemplateDecl4) {
930 ASSERT_TRUE(PrintedDeclMatches(
931 "template<typename T, typename U>"
932 "struct A { T a; U b; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000933 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000934 "template <typename T, typename U> struct A {\n}"));
935 // Should be: with semicolon, with { ... }
936}
937
938TEST(DeclPrinter, TestClassTemplateDecl5) {
939 ASSERT_TRUE(PrintedDeclMatches(
940 "template<int N>"
941 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000942 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000943 "template <int N> struct A {\n}"));
944 // Should be: with semicolon, with { ... }
945}
946
947TEST(DeclPrinter, TestClassTemplateDecl6) {
948 ASSERT_TRUE(PrintedDeclMatches(
949 "template<int N = 42>"
950 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000951 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000952 "template <int N = 42> struct A {\n}"));
953 // Should be: with semicolon, with { ... }
954}
955
956TEST(DeclPrinter, TestClassTemplateDecl7) {
957 ASSERT_TRUE(PrintedDeclMatches(
958 "typedef int MyInt;"
959 "template<MyInt N>"
960 "struct A { int a[N]; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000961 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000962 "template <MyInt N> struct A {\n}"));
963 // Should be: with semicolon, with { ... }
964}
965
966TEST(DeclPrinter, TestClassTemplateDecl8) {
967 ASSERT_TRUE(PrintedDeclMatches(
968 "template<template<typename U> class T> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000969 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000970 "template <template <typename U> class T> struct A {\n}"));
971 // Should be: with semicolon, with { ... }
972}
973
974TEST(DeclPrinter, TestClassTemplateDecl9) {
975 ASSERT_TRUE(PrintedDeclMatches(
976 "template<typename T> struct Z { };"
977 "template<template<typename U> class T = Z> struct A { };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000978 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000979 "template <template <typename U> class T> struct A {\n}"));
980 // Should be: with semicolon, with { ... }
981}
982
983TEST(DeclPrinter, TestClassTemplateDecl10) {
984 ASSERT_TRUE(PrintedDeclCXX11Matches(
985 "template<typename... T>"
986 "struct A { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000987 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000988 "template <typename ... T> struct A {\n}"));
989 // Should be: with semicolon, with { ... }, without spaces before '...'
990}
991
992TEST(DeclPrinter, TestClassTemplateDecl11) {
993 ASSERT_TRUE(PrintedDeclCXX11Matches(
994 "template<typename... T>"
995 "struct A : public T... { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +0000996 classTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +0000997 "template <typename ... T> struct A : public T... {\n}"));
998 // Should be: with semicolon, with { ... }, without spaces before '...'
999}
1000
1001TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
1002 ASSERT_TRUE(PrintedDeclMatches(
1003 "template<typename T, typename U>"
1004 "struct A { T a; U b; };"
1005 "template<typename T>"
1006 "struct A<T, int> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001007 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001008 "struct A {\n}"));
1009 // WRONG; Should be: "template<typename T> struct A<T, int> { ... }"
1010}
1011
1012TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
1013 ASSERT_TRUE(PrintedDeclMatches(
1014 "template<typename T>"
1015 "struct A { T a; };"
1016 "template<typename T>"
1017 "struct A<T *> { T a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001018 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001019 "struct A {\n}"));
1020 // WRONG; Should be: "template<typename T> struct A<T *> { ... }"
1021}
1022
1023TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
1024 ASSERT_TRUE(PrintedDeclMatches(
1025 "template<typename T>"
1026 "struct A { T a; };"
1027 "template<>"
1028 "struct A<int> { int a; };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001029 classTemplateSpecializationDecl().bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001030 "struct A {\n}"));
1031 // WRONG; Should be: "template<> struct A<int> { ... }"
1032}
1033
1034TEST(DeclPrinter, TestFunctionTemplateDecl1) {
1035 ASSERT_TRUE(PrintedDeclMatches(
1036 "template<typename T>"
1037 "void A(T &t);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001038 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001039 "template <typename T> void A(T &t)"));
1040 // Should be: with semicolon
1041}
1042
1043TEST(DeclPrinter, TestFunctionTemplateDecl2) {
1044 ASSERT_TRUE(PrintedDeclMatches(
1045 "template<typename T>"
1046 "void A(T &t) { }",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001047 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001048 "template <typename T> void A(T &t)"));
1049 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001050}
1051
1052TEST(DeclPrinter, TestFunctionTemplateDecl3) {
1053 ASSERT_TRUE(PrintedDeclCXX11Matches(
1054 "template<typename... T>"
1055 "void A(T... a);",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001056 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001057 "template <typename ... T> void A(T a...)"));
1058 // WRONG; Should be: "template <typename ... T> void A(T... a)"
1059 // (not "T a...")
1060 // Should be: with semicolon.
1061}
1062
1063TEST(DeclPrinter, TestFunctionTemplateDecl4) {
1064 ASSERT_TRUE(PrintedDeclMatches(
1065 "struct Z { template<typename T> void A(T t); };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001066 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001067 "template <typename T> void A(T t)"));
1068 // Should be: with semicolon
1069}
1070
1071TEST(DeclPrinter, TestFunctionTemplateDecl5) {
1072 ASSERT_TRUE(PrintedDeclMatches(
1073 "struct Z { template<typename T> void A(T t) {} };",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001074 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001075 "template <typename T> void A(T t)"));
1076 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001077}
1078
1079TEST(DeclPrinter, TestFunctionTemplateDecl6) {
1080 ASSERT_TRUE(PrintedDeclMatches(
1081 "template<typename T >struct Z {"
1082 " template<typename U> void A(U t) {}"
1083 "};",
Daniel Jasper2dc75ed2012-08-24 05:12:34 +00001084 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko2e0b8d92012-08-21 17:47:24 +00001085 "template <typename U> void A(U t)"));
1086 // Should be: with semicolon
Dmitri Gribenko49795ae2012-08-20 23:39:06 +00001087}
1088
1089TEST(DeclPrinter, TestTemplateArgumentList1) {
1090 ASSERT_TRUE(PrintedDeclMatches(
1091 "template<typename T> struct Z {};"
1092 "struct X {};"
1093 "Z<X> A;",
1094 "A",
1095 "Z<X> A"));
1096 // Should be: with semicolon
1097}
1098
1099TEST(DeclPrinter, TestTemplateArgumentList2) {
1100 ASSERT_TRUE(PrintedDeclMatches(
1101 "template<typename T, typename U> struct Z {};"
1102 "struct X {};"
1103 "typedef int Y;"
1104 "Z<X, Y> A;",
1105 "A",
1106 "Z<X, Y> A"));
1107 // Should be: with semicolon
1108}
1109
1110TEST(DeclPrinter, TestTemplateArgumentList3) {
1111 ASSERT_TRUE(PrintedDeclMatches(
1112 "template<typename T> struct Z {};"
1113 "template<typename T> struct X {};"
1114 "Z<X<int> > A;",
1115 "A",
1116 "Z<X<int> > A"));
1117 // Should be: with semicolon
1118}
1119
1120TEST(DeclPrinter, TestTemplateArgumentList4) {
1121 ASSERT_TRUE(PrintedDeclCXX11Matches(
1122 "template<typename T> struct Z {};"
1123 "template<typename T> struct X {};"
1124 "Z<X<int>> A;",
1125 "A",
1126 "Z<X<int> > A"));
1127 // Should be: with semicolon, without extra space in "> >"
1128}
1129
1130TEST(DeclPrinter, TestTemplateArgumentList5) {
1131 ASSERT_TRUE(PrintedDeclCXX11Matches(
1132 "template<typename T> struct Z {};"
1133 "template<typename T> struct X { Z<T> A; };",
1134 "A",
1135 "Z<T> A"));
1136 // Should be: with semicolon
1137}
1138
1139TEST(DeclPrinter, TestTemplateArgumentList6) {
1140 ASSERT_TRUE(PrintedDeclMatches(
1141 "template<template<typename T> class U> struct Z {};"
1142 "template<typename T> struct X {};"
1143 "Z<X> A;",
1144 "A",
1145 "Z<X> A"));
1146 // Should be: with semicolon
1147}
1148
1149TEST(DeclPrinter, TestTemplateArgumentList7) {
1150 ASSERT_TRUE(PrintedDeclCXX11Matches(
1151 "template<template<typename T> class U> struct Z {};"
1152 "template<template<typename T> class U> struct Y {"
1153 " Z<U> A;"
1154 "};",
1155 "A",
1156 "Z<U> A"));
1157 // Should be: with semicolon
1158}
1159
1160TEST(DeclPrinter, TestTemplateArgumentList8) {
1161 ASSERT_TRUE(PrintedDeclCXX11Matches(
1162 "template<typename T> struct Z {};"
1163 "template<template<typename T> class U> struct Y {"
1164 " Z<U<int> > A;"
1165 "};",
1166 "A",
1167 "Z<U<int> > A"));
1168 // Should be: with semicolon
1169}
1170
1171TEST(DeclPrinter, TestTemplateArgumentList9) {
1172 ASSERT_TRUE(PrintedDeclMatches(
1173 "template<unsigned I> struct Z {};"
1174 "Z<0> A;",
1175 "A",
1176 "Z<0> A"));
1177 // Should be: with semicolon
1178}
1179
1180TEST(DeclPrinter, TestTemplateArgumentList10) {
1181 ASSERT_TRUE(PrintedDeclMatches(
1182 "template<unsigned I> struct Z {};"
1183 "template<unsigned I> struct X { Z<I> A; };",
1184 "A",
1185 "Z<I> A"));
1186 // Should be: with semicolon
1187}
1188
1189TEST(DeclPrinter, TestTemplateArgumentList11) {
1190 ASSERT_TRUE(PrintedDeclMatches(
1191 "template<int I> struct Z {};"
1192 "Z<42 * 10 - 420 / 1> A;",
1193 "A",
1194 "Z<42 * 10 - 420 / 1> A"));
1195 // Should be: with semicolon
1196}
1197
1198TEST(DeclPrinter, TestTemplateArgumentList12) {
1199 ASSERT_TRUE(PrintedDeclMatches(
1200 "template<const char *p> struct Z {};"
1201 "extern const char X[] = \"aaa\";"
1202 "Z<X> A;",
1203 "A",
1204 "Z<X> A"));
1205 // Should be: with semicolon
1206}
1207
1208TEST(DeclPrinter, TestTemplateArgumentList13) {
1209 ASSERT_TRUE(PrintedDeclCXX11Matches(
1210 "template<typename... T> struct Z {};"
1211 "template<typename... T> struct X {"
1212 " Z<T...> A;"
1213 "};",
1214 "A",
1215 "Z<T...> A"));
1216 // Should be: with semicolon, without extra space in "> >"
1217}
1218
1219TEST(DeclPrinter, TestTemplateArgumentList14) {
1220 ASSERT_TRUE(PrintedDeclCXX11Matches(
1221 "template<typename... T> struct Z {};"
1222 "template<typename T> struct Y {};"
1223 "template<typename... T> struct X {"
1224 " Z<Y<T>...> A;"
1225 "};",
1226 "A",
1227 "Z<Y<T>...> A"));
1228 // Should be: with semicolon, without extra space in "> >"
1229}
1230
1231TEST(DeclPrinter, TestTemplateArgumentList15) {
1232 ASSERT_TRUE(PrintedDeclCXX11Matches(
1233 "template<unsigned I> struct Z {};"
1234 "template<typename... T> struct X {"
1235 " Z<sizeof...(T)> A;"
1236 "};",
1237 "A",
1238 "Z<sizeof...(T)> A"));
1239 // Should be: with semicolon, without extra space in "> >"
1240}