@@ -260,7 +260,90 @@ TemplateArgument
260
260
19u );
261
261
}
262
262
263
- TEST (Traverse, IgnoreUnlessSpelledInSource) {
263
+ TEST (Traverse, IgnoreUnlessSpelledInSourceStructs) {
264
+ auto AST = buildASTFromCode (R"cpp(
265
+
266
+ struct MyStruct {
267
+ MyStruct();
268
+ MyStruct(int i) {
269
+ MyStruct();
270
+ }
271
+ ~MyStruct();
272
+ };
273
+
274
+ )cpp" );
275
+
276
+ auto BN = ast_matchers::match (
277
+ cxxConstructorDecl (hasName (" MyStruct" ),
278
+ hasParameter (0 , parmVarDecl (hasType (isInteger ()))))
279
+ .bind (" ctor" ),
280
+ AST->getASTContext ());
281
+ EXPECT_EQ (BN.size (), 1u );
282
+
283
+ EXPECT_EQ (dumpASTString (ast_type_traits::TK_IgnoreUnlessSpelledInSource,
284
+ BN[0 ].getNodeAs <Decl>(" ctor" )),
285
+ R"cpp(
286
+ CXXConstructorDecl 'MyStruct'
287
+ |-ParmVarDecl 'i'
288
+ `-CompoundStmt
289
+ `-CXXTemporaryObjectExpr
290
+ )cpp" );
291
+
292
+ EXPECT_EQ (
293
+ dumpASTString (ast_type_traits::TK_AsIs, BN[0 ].getNodeAs <Decl>(" ctor" )),
294
+ R"cpp(
295
+ CXXConstructorDecl 'MyStruct'
296
+ |-ParmVarDecl 'i'
297
+ `-CompoundStmt
298
+ `-ExprWithCleanups
299
+ `-CXXBindTemporaryExpr
300
+ `-CXXTemporaryObjectExpr
301
+ )cpp" );
302
+ }
303
+
304
+ TEST (Traverse, IgnoreUnlessSpelledInSourceReturnStruct) {
305
+
306
+ auto AST = buildASTFromCode (R"cpp(
307
+ struct Retval {
308
+ Retval() {}
309
+ ~Retval() {}
310
+ };
311
+
312
+ Retval someFun();
313
+
314
+ void foo()
315
+ {
316
+ someFun();
317
+ }
318
+ )cpp" );
319
+
320
+ auto BN = ast_matchers::match (functionDecl (hasName (" foo" )).bind (" fn" ),
321
+ AST->getASTContext ());
322
+ EXPECT_EQ (BN.size (), 1u );
323
+
324
+ EXPECT_EQ (dumpASTString (ast_type_traits::TK_IgnoreUnlessSpelledInSource,
325
+ BN[0 ].getNodeAs <Decl>(" fn" )),
326
+ R"cpp(
327
+ FunctionDecl 'foo'
328
+ `-CompoundStmt
329
+ `-CallExpr
330
+ `-DeclRefExpr 'someFun'
331
+ )cpp" );
332
+
333
+ EXPECT_EQ (
334
+ dumpASTString (ast_type_traits::TK_AsIs, BN[0 ].getNodeAs <Decl>(" fn" )),
335
+ R"cpp(
336
+ FunctionDecl 'foo'
337
+ `-CompoundStmt
338
+ `-ExprWithCleanups
339
+ `-CXXBindTemporaryExpr
340
+ `-CallExpr
341
+ `-ImplicitCastExpr
342
+ `-DeclRefExpr 'someFun'
343
+ )cpp" );
344
+ }
345
+
346
+ TEST (Traverse, IgnoreUnlessSpelledInSourceReturns) {
264
347
265
348
auto AST = buildASTFromCode (R"cpp(
266
349
0 commit comments