This change enables a declaration to be conveniently displayed within a debugger when only a pointer to its DeclContext is available. For example, in gdb:
(gdb) p Ctx $1 = (const clang::DeclContext *) 0x14c1a580 (gdb) p Ctx->dumpAsDecl() ClassTemplateSpecializationDecl 0x14c1a540 <t.cpp:1:1, line:7:1> line:2:8 struct ct `-TemplateArgument type 'int' `-BuiltinType 0x14bac420 'int' $2 = void
In the event that the pointed to DeclContext is invalid (that it has an invalid DeclKind as a result of a dangling pointer, memory corruption, etc...) it is not possible to dump its associated declaration. In this case, the DeclContext will be reported as invalid. For example, in gdb:
(gdb) p Ctx->dumpAsDecl() DeclContext 0x14c1a580 <unrecognized Decl kind 127> $3 = void
Interesting DeclContext::dumpDeclContext() is in DeclPrinter.cpp I wonder why these were split like this.