@@ -295,3 +295,49 @@ TEST(TypePrinter, TemplateArgumentsSubstitution_Expressions) {
295295 Ctx, Arg, Param, ArgList.asArray (), Params->getDepth ()));
296296 }
297297}
298+
299+ TEST (TypePrinter, NestedNameSpecifiers) {
300+ constexpr char Code[] = R"cpp(
301+ void level1() {
302+ struct Inner {
303+ Inner(int) {
304+ struct {
305+ union {} u;
306+ } imem;
307+ }
308+ };
309+ }
310+ )cpp" ;
311+
312+ // Types scoped immediately inside a function don't print the function name in
313+ // their scope.
314+ ASSERT_TRUE (PrintedTypeMatches (
315+ Code, {}, varDecl (hasName (" imem" ), hasType (qualType ().bind (" id" ))),
316+ " struct (unnamed)" , [](PrintingPolicy &Policy) {
317+ Policy.FullyQualifiedName = true ;
318+ Policy.AnonymousTagLocations = false ;
319+ }));
320+
321+ ASSERT_TRUE (PrintedTypeMatches (
322+ Code, {}, varDecl (hasName (" imem" ), hasType (qualType ().bind (" id" ))),
323+ " struct (unnamed)" , [](PrintingPolicy &Policy) {
324+ Policy.FullyQualifiedName = false ;
325+ Policy.AnonymousTagLocations = false ;
326+ }));
327+
328+ // Further levels of nesting print the entire scope.
329+ ASSERT_TRUE (PrintedTypeMatches (
330+ Code, {}, fieldDecl (hasName (" u" ), hasType (qualType ().bind (" id" ))),
331+ " union level1()::Inner::Inner(int)::(anonymous struct)::(unnamed)" ,
332+ [](PrintingPolicy &Policy) {
333+ Policy.FullyQualifiedName = true ;
334+ Policy.AnonymousTagLocations = false ;
335+ }));
336+
337+ ASSERT_TRUE (PrintedTypeMatches (
338+ Code, {}, fieldDecl (hasName (" u" ), hasType (qualType ().bind (" id" ))),
339+ " union (unnamed)" , [](PrintingPolicy &Policy) {
340+ Policy.FullyQualifiedName = false ;
341+ Policy.AnonymousTagLocations = false ;
342+ }));
343+ }
0 commit comments