blob: dc1977d87689bac9c23ecf257c67f0c3cdf35f52 [file] [log] [blame]
Dmitri Gribenko309856a2012-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 Jasper6ed1f852012-08-24 05:50:27 +000025#include "llvm/ADT/SmallString.h"
Dmitri Gribenko309856a2012-08-20 23:39:06 +000026#include "gtest/gtest.h"
27
28using namespace clang;
29using namespace ast_matchers;
30using namespace tooling;
31
32namespace {
33
Alex Lorenz35019db2017-11-16 01:28:25 +000034using PrintingPolicyModifier = void (*)(PrintingPolicy &policy);
35
36void PrintDecl(raw_ostream &Out, const ASTContext *Context, const Decl *D,
37 PrintingPolicyModifier PolicyModifier) {
Dmitri Gribenko309856a2012-08-20 23:39:06 +000038 PrintingPolicy Policy = Context->getPrintingPolicy();
Dmitri Gribenkoa93a7e82012-08-21 17:36:32 +000039 Policy.TerseOutput = true;
Alex Lorenz35019db2017-11-16 01:28:25 +000040 if (PolicyModifier)
41 PolicyModifier(Policy);
Dmitri Gribenko309856a2012-08-20 23:39:06 +000042 D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
43}
44
45class PrintMatch : public MatchFinder::MatchCallback {
46 SmallString<1024> Printed;
47 unsigned NumFoundDecls;
Alex Lorenz35019db2017-11-16 01:28:25 +000048 PrintingPolicyModifier PolicyModifier;
Dmitri Gribenko309856a2012-08-20 23:39:06 +000049
50public:
Alex Lorenz35019db2017-11-16 01:28:25 +000051 PrintMatch(PrintingPolicyModifier PolicyModifier)
52 : NumFoundDecls(0), PolicyModifier(PolicyModifier) {}
Dmitri Gribenko309856a2012-08-20 23:39:06 +000053
Alexander Kornienko34eb2072015-04-11 02:00:23 +000054 void run(const MatchFinder::MatchResult &Result) override {
Alexander Kornienko7cdc7052016-12-13 16:19:34 +000055 const Decl *D = Result.Nodes.getNodeAs<Decl>("id");
Dmitri Gribenko309856a2012-08-20 23:39:06 +000056 if (!D || D->isImplicit())
57 return;
58 NumFoundDecls++;
59 if (NumFoundDecls > 1)
60 return;
61
62 llvm::raw_svector_ostream Out(Printed);
Alex Lorenz35019db2017-11-16 01:28:25 +000063 PrintDecl(Out, Result.Context, D, PolicyModifier);
Dmitri Gribenko309856a2012-08-20 23:39:06 +000064 }
65
66 StringRef getPrinted() const {
67 return Printed;
68 }
69
70 unsigned getNumFoundDecls() const {
71 return NumFoundDecls;
72 }
73};
74
Alex Lorenz35019db2017-11-16 01:28:25 +000075::testing::AssertionResult
76PrintedDeclMatches(StringRef Code, const std::vector<std::string> &Args,
77 const DeclarationMatcher &NodeMatch,
78 StringRef ExpectedPrinted, StringRef FileName,
79 PrintingPolicyModifier PolicyModifier = nullptr) {
80 PrintMatch Printer(PolicyModifier);
Dmitri Gribenko309856a2012-08-20 23:39:06 +000081 MatchFinder Finder;
82 Finder.addMatcher(NodeMatch, &Printer);
Ahmed Charlesb8984322014-03-07 20:03:18 +000083 std::unique_ptr<FrontendActionFactory> Factory(
84 newFrontendActionFactory(&Finder));
Dmitri Gribenko309856a2012-08-20 23:39:06 +000085
Fariborz Jahaniane0586a52012-10-18 19:12:17 +000086 if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName))
Saleem Abdulrasool8a8454b2014-01-25 20:04:44 +000087 return testing::AssertionFailure()
88 << "Parsing error in \"" << Code.str() << "\"";
Dmitri Gribenko309856a2012-08-20 23:39:06 +000089
90 if (Printer.getNumFoundDecls() == 0)
91 return testing::AssertionFailure()
92 << "Matcher didn't find any declarations";
93
94 if (Printer.getNumFoundDecls() > 1)
95 return testing::AssertionFailure()
96 << "Matcher should match only one declaration "
97 "(found " << Printer.getNumFoundDecls() << ")";
98
99 if (Printer.getPrinted() != ExpectedPrinted)
100 return ::testing::AssertionFailure()
Saleem Abdulrasool8a8454b2014-01-25 20:04:44 +0000101 << "Expected \"" << ExpectedPrinted.str() << "\", "
102 "got \"" << Printer.getPrinted().str() << "\"";
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000103
104 return ::testing::AssertionSuccess();
105}
106
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000107::testing::AssertionResult PrintedDeclCXX98Matches(StringRef Code,
108 StringRef DeclName,
109 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000110 std::vector<std::string> Args(1, "-std=c++98");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000111 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000112 Args,
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000113 namedDecl(hasName(DeclName)).bind("id"),
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000114 ExpectedPrinted,
115 "input.cc");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000116}
117
Alex Lorenz35019db2017-11-16 01:28:25 +0000118::testing::AssertionResult
119PrintedDeclCXX98Matches(StringRef Code, const DeclarationMatcher &NodeMatch,
120 StringRef ExpectedPrinted,
121 PrintingPolicyModifier PolicyModifier = nullptr) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000122 std::vector<std::string> Args(1, "-std=c++98");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000123 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000124 Args,
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000125 NodeMatch,
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000126 ExpectedPrinted,
Alex Lorenz35019db2017-11-16 01:28:25 +0000127 "input.cc",
128 PolicyModifier);
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000129}
130
131::testing::AssertionResult PrintedDeclCXX11Matches(StringRef Code,
132 StringRef DeclName,
133 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000134 std::vector<std::string> Args(1, "-std=c++11");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000135 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000136 Args,
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000137 namedDecl(hasName(DeclName)).bind("id"),
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000138 ExpectedPrinted,
139 "input.cc");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000140}
141
142::testing::AssertionResult PrintedDeclCXX11Matches(
143 StringRef Code,
144 const DeclarationMatcher &NodeMatch,
145 StringRef ExpectedPrinted) {
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000146 std::vector<std::string> Args(1, "-std=c++11");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000147 return PrintedDeclMatches(Code,
Dmitri Gribenko454a43c2012-08-31 03:23:26 +0000148 Args,
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000149 NodeMatch,
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000150 ExpectedPrinted,
151 "input.cc");
152}
153
NAKAMURA Takumi7d2da0b2014-02-16 10:16:09 +0000154::testing::AssertionResult PrintedDeclCXX11nonMSCMatches(
155 StringRef Code,
156 const DeclarationMatcher &NodeMatch,
157 StringRef ExpectedPrinted) {
158 std::vector<std::string> Args(1, "-std=c++11");
159 Args.push_back("-fno-delayed-template-parsing");
160 return PrintedDeclMatches(Code,
161 Args,
162 NodeMatch,
163 ExpectedPrinted,
164 "input.cc");
165}
166
David Majnemer8423df92015-06-05 22:40:53 +0000167::testing::AssertionResult
168PrintedDeclCXX1ZMatches(StringRef Code, const DeclarationMatcher &NodeMatch,
169 StringRef ExpectedPrinted) {
170 std::vector<std::string> Args(1, "-std=c++1z");
171 return PrintedDeclMatches(Code,
172 Args,
173 NodeMatch,
174 ExpectedPrinted,
175 "input.cc");
176}
177
Fariborz Jahaniane0586a52012-10-18 19:12:17 +0000178::testing::AssertionResult PrintedDeclObjCMatches(
179 StringRef Code,
180 const DeclarationMatcher &NodeMatch,
181 StringRef ExpectedPrinted) {
182 std::vector<std::string> Args(1, "");
183 return PrintedDeclMatches(Code,
184 Args,
185 NodeMatch,
186 ExpectedPrinted,
187 "input.m");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000188}
189
190} // unnamed namespace
191
Dmitri Gribenko5ea34fc2014-03-03 13:21:00 +0000192TEST(DeclPrinter, TestTypedef1) {
193 ASSERT_TRUE(PrintedDeclCXX98Matches(
194 "typedef int A;",
195 "A",
196 "typedef int A"));
197 // Should be: with semicolon
198}
199
200TEST(DeclPrinter, TestTypedef2) {
201 ASSERT_TRUE(PrintedDeclCXX98Matches(
202 "typedef const char *A;",
203 "A",
204 "typedef const char *A"));
205 // Should be: with semicolon
206}
207
208TEST(DeclPrinter, TestTypedef3) {
209 ASSERT_TRUE(PrintedDeclCXX98Matches(
210 "template <typename Y> class X {};"
211 "typedef X<int> A;",
212 "A",
213 "typedef X<int> A"));
214 // Should be: with semicolon
215}
216
217TEST(DeclPrinter, TestTypedef4) {
218 ASSERT_TRUE(PrintedDeclCXX98Matches(
219 "namespace X { class Y {}; }"
220 "typedef X::Y A;",
221 "A",
222 "typedef X::Y A"));
223 // Should be: with semicolon
224}
225
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000226TEST(DeclPrinter, TestNamespace1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000227 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000228 "namespace A { int B; }",
229 "A",
230 "namespace A {\n}"));
231 // Should be: with { ... }
232}
233
234TEST(DeclPrinter, TestNamespace2) {
235 ASSERT_TRUE(PrintedDeclCXX11Matches(
236 "inline namespace A { int B; }",
237 "A",
238 "inline namespace A {\n}"));
239 // Should be: with { ... }
240}
241
242TEST(DeclPrinter, TestNamespaceAlias1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000243 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000244 "namespace Z { }"
245 "namespace A = Z;",
246 "A",
247 "namespace A = Z"));
248 // Should be: with semicolon
249}
250
251TEST(DeclPrinter, TestNamespaceAlias2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000252 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000253 "namespace X { namespace Y {} }"
254 "namespace A = X::Y;",
255 "A",
256 "namespace A = X::Y"));
257 // Should be: with semicolon
258}
259
260TEST(DeclPrinter, TestCXXRecordDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000261 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000262 "class A { int a; };",
263 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000264 "class A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000265}
266
267TEST(DeclPrinter, TestCXXRecordDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000268 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000269 "struct A { int a; };",
270 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000271 "struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000272}
273
274TEST(DeclPrinter, TestCXXRecordDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000275 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000276 "union A { int a; };",
277 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000278 "union A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000279}
280
281TEST(DeclPrinter, TestCXXRecordDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000282 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000283 "class Z { int a; };"
284 "class A : Z { int b; };",
285 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000286 "class A : Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000287}
288
289TEST(DeclPrinter, TestCXXRecordDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000290 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000291 "struct Z { int a; };"
292 "struct A : Z { int b; };",
293 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000294 "struct A : Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000295}
296
297TEST(DeclPrinter, TestCXXRecordDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000298 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000299 "class Z { int a; };"
300 "class A : public Z { int b; };",
301 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000302 "class A : public Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000303}
304
305TEST(DeclPrinter, TestCXXRecordDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000306 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000307 "class Z { int a; };"
308 "class A : protected Z { int b; };",
309 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000310 "class A : protected Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000311}
312
313TEST(DeclPrinter, TestCXXRecordDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000314 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000315 "class Z { int a; };"
316 "class A : private Z { int b; };",
317 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000318 "class A : private Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000319}
320
321TEST(DeclPrinter, TestCXXRecordDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000322 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000323 "class Z { int a; };"
324 "class A : virtual Z { int b; };",
325 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000326 "class A : virtual Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000327}
328
329TEST(DeclPrinter, TestCXXRecordDecl10) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000330 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000331 "class Z { int a; };"
332 "class A : virtual public Z { int b; };",
333 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000334 "class A : virtual public Z {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000335}
336
337TEST(DeclPrinter, TestCXXRecordDecl11) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000338 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000339 "class Z { int a; };"
340 "class Y : virtual public Z { int b; };"
341 "class A : virtual public Z, private Y { int c; };",
342 "A",
Serge Pavlova67a4d22016-11-10 08:49:37 +0000343 "class A : virtual public Z, private Y {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000344}
345
346TEST(DeclPrinter, TestFunctionDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000347 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000348 "void A();",
349 "A",
350 "void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000351}
352
353TEST(DeclPrinter, TestFunctionDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000354 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000355 "void A() {}",
356 "A",
357 "void A()"));
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000358}
359
360TEST(DeclPrinter, TestFunctionDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000361 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000362 "void Z();"
363 "void A() { Z(); }",
364 "A",
365 "void A()"));
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000366}
367
368TEST(DeclPrinter, TestFunctionDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000369 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000370 "extern void A();",
371 "A",
372 "extern void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000373}
374
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000375TEST(DeclPrinter, TestFunctionDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000376 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000377 "static void A();",
378 "A",
379 "static void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000380}
381
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000382TEST(DeclPrinter, TestFunctionDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000383 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000384 "inline void A();",
385 "A",
386 "inline void A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000387}
388
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000389TEST(DeclPrinter, TestFunctionDecl7) {
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000390 ASSERT_TRUE(PrintedDeclCXX11Matches(
391 "constexpr int A(int a);",
392 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000393 "constexpr int A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000394}
395
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000396TEST(DeclPrinter, TestFunctionDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000397 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000398 "void A(int a);",
399 "A",
400 "void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000401}
402
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000403TEST(DeclPrinter, TestFunctionDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000404 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000405 "void A(...);",
406 "A",
407 "void A(...)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000408}
409
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000410TEST(DeclPrinter, TestFunctionDecl10) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000411 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000412 "void A(int a, ...);",
413 "A",
414 "void A(int a, ...)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000415}
416
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000417TEST(DeclPrinter, TestFunctionDecl11) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000418 ASSERT_TRUE(PrintedDeclCXX98Matches(
David Majnemerd4328de2014-01-14 08:18:49 +0000419 "typedef long ssize_t;"
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000420 "typedef int *pInt;"
David Majnemerd4328de2014-01-14 08:18:49 +0000421 "void A(int a, pInt b, ssize_t c);",
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000422 "A",
David Majnemerd4328de2014-01-14 08:18:49 +0000423 "void A(int a, pInt b, ssize_t c)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000424}
425
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000426TEST(DeclPrinter, TestFunctionDecl12) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000427 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000428 "void A(int a, int b = 0);",
429 "A",
430 "void A(int a, int b = 0)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000431}
432
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000433TEST(DeclPrinter, TestFunctionDecl13) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000434 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000435 "void (*A(int a))(int b);",
436 "A",
437 "void (*A(int a))(int)"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000438 // Should be: with parameter name (?)
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000439}
440
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +0000441TEST(DeclPrinter, TestFunctionDecl14) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000442 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000443 "template<typename T>"
444 "void A(T t) { }"
445 "template<>"
446 "void A(int N) { }",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000447 functionDecl(hasName("A"), isExplicitTemplateSpecialization()).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000448 "template<> void A<int>(int N)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000449}
450
451
452TEST(DeclPrinter, TestCXXConstructorDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000453 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000454 "struct A {"
455 " A();"
456 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000457 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000458 "A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000459}
460
461TEST(DeclPrinter, TestCXXConstructorDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000462 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000463 "struct A {"
464 " A(int a);"
465 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000466 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000467 "A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000468}
469
470TEST(DeclPrinter, TestCXXConstructorDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000471 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000472 "struct A {"
473 " A(const A &a);"
474 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000475 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000476 "A(const A &a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000477}
478
479TEST(DeclPrinter, TestCXXConstructorDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000480 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000481 "struct A {"
482 " A(const A &a, int = 0);"
483 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000484 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000485 "A(const A &a, int = 0)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000486}
487
Alex Lorenz35019db2017-11-16 01:28:25 +0000488TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer) {
489 ASSERT_TRUE(PrintedDeclCXX98Matches(
490 "struct A {"
491 " int m;"
492 " A() : m(2) {}"
493 "};",
494 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
495 "A()"));
496}
497
498TEST(DeclPrinter, TestCXXConstructorDeclWithMemberInitializer_NoTerseOutput) {
499 ASSERT_TRUE(PrintedDeclCXX98Matches(
500 "struct A {"
501 " int m;"
502 " A() : m(2) {}"
503 "};",
504 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
505 "A() : m(2) {\n}\n",
506 [](PrintingPolicy &Policy){ Policy.TerseOutput = false; }));
507}
508
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000509TEST(DeclPrinter, TestCXXConstructorDecl5) {
510 ASSERT_TRUE(PrintedDeclCXX11Matches(
511 "struct A {"
512 " A(const A &&a);"
513 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000514 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000515 "A(const A &&a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000516}
517
518TEST(DeclPrinter, TestCXXConstructorDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000519 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000520 "struct A {"
521 " explicit A(int a);"
522 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000523 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian69c403c2012-12-05 22:19:06 +0000524 "explicit A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000525}
526
527TEST(DeclPrinter, TestCXXConstructorDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000528 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000529 "struct A {"
530 " constexpr A();"
531 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000532 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000533 "constexpr A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000534}
535
536TEST(DeclPrinter, TestCXXConstructorDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000537 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000538 "struct A {"
539 " A() = default;"
540 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000541 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Richard Smithbd305122012-12-11 01:14:52 +0000542 "A() = default"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000543}
544
545TEST(DeclPrinter, TestCXXConstructorDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000546 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000547 "struct A {"
548 " A() = delete;"
549 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000550 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000551 "A() = delete"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000552}
553
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000554TEST(DeclPrinter, TestCXXConstructorDecl10) {
555 ASSERT_TRUE(PrintedDeclCXX11Matches(
556 "template<typename... T>"
557 "struct A {"
558 " A(const A &a);"
559 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000560 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Fariborz Jahanian14ef4792012-12-05 19:54:11 +0000561 "A<T...>(const A<T...> &a)"));
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000562}
563
564TEST(DeclPrinter, TestCXXConstructorDecl11) {
NAKAMURA Takumi7d2da0b2014-02-16 10:16:09 +0000565 ASSERT_TRUE(PrintedDeclCXX11nonMSCMatches(
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000566 "template<typename... T>"
567 "struct A : public T... {"
568 " A(T&&... ts) : T(ts)... {}"
569 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000570 cxxConstructorDecl(ofClass(hasName("A"))).bind("id"),
Alex Lorenz35019db2017-11-16 01:28:25 +0000571 "A<T...>(T &&...ts)"));
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000572}
Dmitri Gribenko340c0f62012-08-24 00:26:25 +0000573
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000574TEST(DeclPrinter, TestCXXDestructorDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000575 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000576 "struct A {"
577 " ~A();"
578 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000579 cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000580 "~A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000581}
582
583TEST(DeclPrinter, TestCXXDestructorDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000584 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000585 "struct A {"
586 " virtual ~A();"
587 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000588 cxxDestructorDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer2907b082014-02-25 18:49:49 +0000589 "virtual ~A()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000590}
591
592TEST(DeclPrinter, TestCXXConversionDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000593 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000594 "struct A {"
595 " operator int();"
596 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000597 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000598 "operator int()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000599}
600
601TEST(DeclPrinter, TestCXXConversionDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000602 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000603 "struct A {"
604 " operator bool();"
605 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000606 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000607 "operator bool()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000608}
609
610TEST(DeclPrinter, TestCXXConversionDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000611 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000612 "struct Z {};"
613 "struct A {"
614 " operator Z();"
615 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000616 cxxMethodDecl(ofClass(hasName("A"))).bind("id"),
Benjamin Kramer00e8a192014-02-25 18:03:55 +0000617 "operator Z()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000618}
619
620TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000621 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000622 "namespace std { typedef decltype(sizeof(int)) size_t; }"
623 "struct Z {"
624 " void *operator new(std::size_t);"
625 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000626 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000627 "void *operator new(std::size_t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000628}
629
630TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000631 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000632 "namespace std { typedef decltype(sizeof(int)) size_t; }"
633 "struct Z {"
634 " void *operator new[](std::size_t);"
635 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000636 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000637 "void *operator new[](std::size_t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000638}
639
640TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000641 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000642 "struct Z {"
643 " void operator delete(void *);"
644 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000645 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000646 "void operator delete(void *) noexcept"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000647 // Should be: without noexcept?
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000648}
649
650TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000651 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000652 "struct Z {"
653 " void operator delete(void *);"
654 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000655 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000656 "void operator delete(void *)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000657}
658
659TEST(DeclPrinter, TestCXXMethodDecl_AllocationFunction5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000660 ASSERT_TRUE(PrintedDeclCXX11Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000661 "struct Z {"
662 " void operator delete[](void *);"
663 "};",
Aaron Ballman512fb642015-09-17 13:30:52 +0000664 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000665 "void operator delete[](void *) noexcept"));
Serge Pavlova67a4d22016-11-10 08:49:37 +0000666 // Should be: without noexcept?
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000667}
668
669TEST(DeclPrinter, TestCXXMethodDecl_Operator1) {
670 const char *OperatorNames[] = {
671 "+", "-", "*", "/", "%", "^", "&", "|",
672 "=", "<", ">", "+=", "-=", "*=", "/=", "%=",
673 "^=", "&=", "|=", "<<", ">>", ">>=", "<<=", "==", "!=",
674 "<=", ">=", "&&", "||", ",", "->*",
675 "()", "[]"
676 };
677
678 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
679 SmallString<128> Code;
680 Code.append("struct Z { void operator");
681 Code.append(OperatorNames[i]);
682 Code.append("(Z z); };");
683
684 SmallString<128> Expected;
685 Expected.append("void operator");
686 Expected.append(OperatorNames[i]);
687 Expected.append("(Z z)");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000688
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000689 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000690 Code,
Aaron Ballman512fb642015-09-17 13:30:52 +0000691 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000692 Expected));
693 }
694}
695
696TEST(DeclPrinter, TestCXXMethodDecl_Operator2) {
697 const char *OperatorNames[] = {
698 "~", "!", "++", "--", "->"
699 };
700
701 for (unsigned i = 0, e = llvm::array_lengthof(OperatorNames); i != e; ++i) {
702 SmallString<128> Code;
703 Code.append("struct Z { void operator");
704 Code.append(OperatorNames[i]);
705 Code.append("(); };");
706
707 SmallString<128> Expected;
708 Expected.append("void operator");
709 Expected.append(OperatorNames[i]);
710 Expected.append("()");
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000711
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000712 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000713 Code,
Aaron Ballman512fb642015-09-17 13:30:52 +0000714 cxxMethodDecl(ofClass(hasName("Z"))).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000715 Expected));
716 }
717}
718
719TEST(DeclPrinter, TestCXXMethodDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000720 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000721 "struct Z {"
722 " void A(int a);"
723 "};",
724 "A",
725 "void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000726}
727
728TEST(DeclPrinter, TestCXXMethodDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000729 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000730 "struct Z {"
731 " virtual void A(int a);"
732 "};",
733 "A",
734 "virtual void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000735}
736
737TEST(DeclPrinter, TestCXXMethodDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000738 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000739 "struct Z {"
740 " virtual void A(int a);"
741 "};"
742 "struct ZZ : Z {"
743 " void A(int a);"
744 "};",
745 "ZZ::A",
746 "void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000747 // TODO: should we print "virtual"?
748}
749
750TEST(DeclPrinter, TestCXXMethodDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000751 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000752 "struct Z {"
753 " inline void A(int a);"
754 "};",
755 "A",
756 "inline void A(int a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000757}
758
759TEST(DeclPrinter, TestCXXMethodDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000760 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000761 "struct Z {"
762 " virtual void A(int a) = 0;"
763 "};",
764 "A",
765 "virtual void A(int a) = 0"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000766}
767
768TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000769 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000770 "struct Z {"
771 " void A(int a) const;"
772 "};",
773 "A",
774 "void A(int a) const"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000775}
776
777TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000778 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000779 "struct Z {"
780 " void A(int a) volatile;"
781 "};",
782 "A",
783 "void A(int a) volatile"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000784}
785
786TEST(DeclPrinter, TestCXXMethodDecl_CVQualifier3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000787 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000788 "struct Z {"
789 " void A(int a) const volatile;"
790 "};",
791 "A",
792 "void A(int a) const volatile"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000793}
794
795TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier1) {
796 ASSERT_TRUE(PrintedDeclCXX11Matches(
797 "struct Z {"
798 " void A(int a) &;"
799 "};",
800 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000801 "void A(int a) &"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000802}
803
804TEST(DeclPrinter, TestCXXMethodDecl_RefQualifier2) {
805 ASSERT_TRUE(PrintedDeclCXX11Matches(
806 "struct Z {"
807 " void A(int a) &&;"
808 "};",
809 "A",
Benjamin Kramer2907b082014-02-25 18:49:49 +0000810 "void A(int a) &&"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000811}
812
813TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000814 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000815 "struct Z {"
816 " void A(int a) throw();"
817 "};",
818 "A",
819 "void A(int a) throw()"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000820}
821
822TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000823 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000824 "struct Z {"
825 " void A(int a) throw(int);"
826 "};",
827 "A",
828 "void A(int a) throw(int)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000829}
830
831TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000832 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000833 "class ZZ {};"
834 "struct Z {"
835 " void A(int a) throw(ZZ, int);"
836 "};",
837 "A",
838 "void A(int a) throw(ZZ, int)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000839}
840
841TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification4) {
842 ASSERT_TRUE(PrintedDeclCXX11Matches(
843 "struct Z {"
844 " void A(int a) noexcept;"
845 "};",
846 "A",
847 "void A(int a) noexcept"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000848}
849
850TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification5) {
851 ASSERT_TRUE(PrintedDeclCXX11Matches(
852 "struct Z {"
853 " void A(int a) noexcept(true);"
854 "};",
855 "A",
856 "void A(int a) noexcept(trueA(int a) noexcept(true)"));
857 // WRONG; Should be: "void A(int a) noexcept(true);"
858}
859
860TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification6) {
861 ASSERT_TRUE(PrintedDeclCXX11Matches(
862 "struct Z {"
863 " void A(int a) noexcept(1 < 2);"
864 "};",
865 "A",
866 "void A(int a) noexcept(1 < 2A(int a) noexcept(1 < 2)"));
867 // WRONG; Should be: "void A(int a) noexcept(1 < 2);"
868}
869
870TEST(DeclPrinter, TestFunctionDecl_ExceptionSpecification7) {
871 ASSERT_TRUE(PrintedDeclCXX11Matches(
872 "template<int N>"
873 "struct Z {"
874 " void A(int a) noexcept(N < 2);"
875 "};",
876 "A",
877 "void A(int a) noexcept(N < 2A(int a) noexcept(N < 2)"));
878 // WRONG; Should be: "void A(int a) noexcept(N < 2);"
879}
880
881TEST(DeclPrinter, TestVarDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000882 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000883 "char *const (*(*A)[5])(int);",
884 "A",
885 "char *const (*(*A)[5])(int)"));
886 // Should be: with semicolon
887}
888
889TEST(DeclPrinter, TestVarDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000890 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000891 "void (*A)() throw(int);",
892 "A",
893 "void (*A)() throw(int)"));
894 // Should be: with semicolon
895}
896
897TEST(DeclPrinter, TestVarDecl3) {
898 ASSERT_TRUE(PrintedDeclCXX11Matches(
899 "void (*A)() noexcept;",
900 "A",
901 "void (*A)() noexcept"));
902 // Should be: with semicolon
903}
904
905TEST(DeclPrinter, TestFieldDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000906 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000907 "template<typename T>"
908 "struct Z { T A; };",
909 "A",
910 "T A"));
911 // Should be: with semicolon
912}
913
914TEST(DeclPrinter, TestFieldDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000915 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000916 "template<int N>"
917 "struct Z { int A[N]; };",
918 "A",
919 "int A[N]"));
920 // Should be: with semicolon
921}
922
923TEST(DeclPrinter, TestClassTemplateDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000924 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000925 "template<typename T>"
926 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000927 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000928 "template <typename T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000929}
930
931TEST(DeclPrinter, TestClassTemplateDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000932 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000933 "template<typename T = int>"
934 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000935 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000936 "template <typename T = int> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000937}
938
939TEST(DeclPrinter, TestClassTemplateDecl3) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000940 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000941 "template<class T>"
942 "struct A { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000943 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000944 "template <class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000945}
946
947TEST(DeclPrinter, TestClassTemplateDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000948 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000949 "template<typename T, typename U>"
950 "struct A { T a; U b; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000951 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000952 "template <typename T, typename U> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000953}
954
955TEST(DeclPrinter, TestClassTemplateDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000956 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000957 "template<int N>"
958 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000959 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000960 "template <int N> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000961}
962
963TEST(DeclPrinter, TestClassTemplateDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000964 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000965 "template<int N = 42>"
966 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000967 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000968 "template <int N = 42> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000969}
970
971TEST(DeclPrinter, TestClassTemplateDecl7) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000972 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000973 "typedef int MyInt;"
974 "template<MyInt N>"
975 "struct A { int a[N]; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000976 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000977 "template <MyInt N> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000978}
979
980TEST(DeclPrinter, TestClassTemplateDecl8) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000981 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000982 "template<template<typename U> class T> struct A { };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000983 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000984 "template <template <typename U> class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000985}
986
987TEST(DeclPrinter, TestClassTemplateDecl9) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +0000988 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000989 "template<typename T> struct Z { };"
990 "template<template<typename U> class T = Z> struct A { };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000991 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +0000992 "template <template <typename U> class T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +0000993}
994
995TEST(DeclPrinter, TestClassTemplateDecl10) {
996 ASSERT_TRUE(PrintedDeclCXX11Matches(
997 "template<typename... T>"
998 "struct A { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +0000999 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001000 "template <typename ...T> struct A {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001001}
1002
1003TEST(DeclPrinter, TestClassTemplateDecl11) {
1004 ASSERT_TRUE(PrintedDeclCXX11Matches(
1005 "template<typename... T>"
1006 "struct A : public T... { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001007 classTemplateDecl(hasName("A")).bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001008 "template <typename ...T> struct A : public T... {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001009}
1010
1011TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001012 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001013 "template<typename T, typename U>"
1014 "struct A { T a; U b; };"
1015 "template<typename T>"
1016 "struct A<T, int> { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001017 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001018 "template <typename T> struct A<T, int> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001019}
1020
1021TEST(DeclPrinter, TestClassTemplatePartialSpecializationDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001022 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001023 "template<typename T>"
1024 "struct A { T a; };"
1025 "template<typename T>"
1026 "struct A<T *> { T a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001027 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001028 "template <typename T> struct A<type-parameter-0-0 *> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001029 // WRONG; Should be: "template<typename T> struct A<T *> { ... }"
1030}
1031
1032TEST(DeclPrinter, TestClassTemplateSpecializationDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001033 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001034 "template<typename T>"
1035 "struct A { T a; };"
1036 "template<>"
1037 "struct A<int> { int a; };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001038 classTemplateSpecializationDecl().bind("id"),
Serge Pavlova67a4d22016-11-10 08:49:37 +00001039 "template<> struct A<int> {}"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001040}
1041
1042TEST(DeclPrinter, TestFunctionTemplateDecl1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001043 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001044 "template<typename T>"
1045 "void A(T &t);",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001046 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001047 "template <typename T> void A(T &t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001048}
1049
1050TEST(DeclPrinter, TestFunctionTemplateDecl2) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001051 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001052 "template<typename T>"
1053 "void A(T &t) { }",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001054 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001055 "template <typename T> void A(T &t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001056}
1057
1058TEST(DeclPrinter, TestFunctionTemplateDecl3) {
1059 ASSERT_TRUE(PrintedDeclCXX11Matches(
1060 "template<typename... T>"
1061 "void A(T... a);",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001062 functionTemplateDecl(hasName("A")).bind("id"),
Richard Smitha4bb2922014-07-23 03:17:06 +00001063 "template <typename ...T> void A(T ...a)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001064}
1065
1066TEST(DeclPrinter, TestFunctionTemplateDecl4) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001067 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001068 "struct Z { template<typename T> void A(T t); };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001069 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001070 "template <typename T> void A(T t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001071}
1072
1073TEST(DeclPrinter, TestFunctionTemplateDecl5) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001074 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001075 "struct Z { template<typename T> void A(T t) {} };",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001076 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001077 "template <typename T> void A(T t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001078}
1079
1080TEST(DeclPrinter, TestFunctionTemplateDecl6) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001081 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001082 "template<typename T >struct Z {"
1083 " template<typename U> void A(U t) {}"
1084 "};",
Daniel Jasperbd3d76d2012-08-24 05:12:34 +00001085 functionTemplateDecl(hasName("A")).bind("id"),
Dmitri Gribenkoa9a2af72012-08-21 17:47:24 +00001086 "template <typename U> void A(U t)"));
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001087}
1088
1089TEST(DeclPrinter, TestTemplateArgumentList1) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001090 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001091 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001100 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001101 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001111 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001112 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001131 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001132 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001140 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001141 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001150 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001151 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001161 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001162 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001172 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001173 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001181 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001182 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001190 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001191 "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) {
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001199 ASSERT_TRUE(PrintedDeclCXX98Matches(
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001200 "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"));
Richard Smitha4bb2922014-07-23 03:17:06 +00001216 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001217}
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"));
Richard Smitha4bb2922014-07-23 03:17:06 +00001228 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001229}
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"));
Richard Smitha4bb2922014-07-23 03:17:06 +00001239 // Should be: with semicolon
Dmitri Gribenko309856a2012-08-20 23:39:06 +00001240}
Dmitri Gribenkobda79e52012-08-31 03:05:44 +00001241
David Majnemer8423df92015-06-05 22:40:53 +00001242TEST(DeclPrinter, TestStaticAssert1) {
1243 ASSERT_TRUE(PrintedDeclCXX1ZMatches(
1244 "static_assert(true);",
1245 staticAssertDecl().bind("id"),
1246 "static_assert(true)"));
1247}
1248
Fariborz Jahaniane0586a52012-10-18 19:12:17 +00001249TEST(DeclPrinter, TestObjCMethod1) {
1250 ASSERT_TRUE(PrintedDeclObjCMatches(
1251 "__attribute__((objc_root_class)) @interface X\n"
1252 "- (int)A:(id)anObject inRange:(long)range;\n"
1253 "@end\n"
1254 "@implementation X\n"
1255 "- (int)A:(id)anObject inRange:(long)range { int printThis; return 0; }\n"
1256 "@end\n",
1257 namedDecl(hasName("A:inRange:"),
1258 hasDescendant(namedDecl(hasName("printThis")))).bind("id"),
Alex Lorenzbbf4f702017-06-02 15:02:59 +00001259 "- (int)A:(id)anObject inRange:(long)range"));
Fariborz Jahaniane0586a52012-10-18 19:12:17 +00001260}
1261
Fariborz Jahanian44194492012-12-20 02:20:09 +00001262TEST(DeclPrinter, TestObjCProtocol1) {
1263 ASSERT_TRUE(PrintedDeclObjCMatches(
1264 "@protocol P1, P2;",
1265 namedDecl(hasName("P1")).bind("id"),
1266 "@protocol P1;\n"));
1267 ASSERT_TRUE(PrintedDeclObjCMatches(
1268 "@protocol P1, P2;",
1269 namedDecl(hasName("P2")).bind("id"),
1270 "@protocol P2;\n"));
1271}
1272
1273TEST(DeclPrinter, TestObjCProtocol2) {
1274 ASSERT_TRUE(PrintedDeclObjCMatches(
1275 "@protocol P2 @end"
1276 "@protocol P1<P2> @end",
1277 namedDecl(hasName("P1")).bind("id"),
1278 "@protocol P1<P2>\n@end"));
1279}