<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/68670>68670</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-extdef-mapping] assertion failed on ElaboratedType NestedNameSpecifier
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          danix800
      </td>
    </tr>
</table>

<pre>
    Testcase:
```c
// test.cpp

template <bool C, typename T>
struct cond {
  typedef T Ty;
};

template <typename _T>
class M;

template <typename T,
          typename U =
              typename cond<T::S, int>::Ty>
class R;

template <typename T>
class B {
  void f(R<const M<T>> arg);
};

template <typename T>
void B<T>::f(R<const M<T>> arg) {}
```

Run with `clang-extdef-mapping test.cpp`, crash dump:
```
clang-extdef-mapping: /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/NestedNameSpecifier.cpp:309: void clang::NestedNameSpecifier::print(llvm::raw_ostream &, const clang::PrintingPolicy &, bool) const: Assertion `!isa<ElaboratedType>(T) && "Elaborated type in nested-name-specifier"' failed.
 #0 0x00007f01f0e0706a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x00007f01f0e0726b PrintStackTraceSignalHandler(void*) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00007f01f0e05586 llvm::sys::RunSignalHandlers() /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00007f01f0e07a85 SignalHandler(int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f01f085afd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
 #5 0x00007f01f08a9d3c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f01f085af32 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f01f0845472 abort ./stdlib/abort.c:81:7
 #8 0x00007f01f0845395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f01f0853e32 (/lib/x86_64-linux-gnu/libc.so.6+0x34e32)
#10 0x00007f01f2ad54e7 clang::NestedNameSpecifier::print(llvm::raw_ostream&, clang::PrintingPolicy const&, bool) const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/NestedNameSpecifier.cpp:311:50
#11 0x00007f01f2ba91b6 (anonymous namespace)::StmtPrinter::VisitDependentScopeDeclRefExpr(clang::DependentScopeDeclRefExpr*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:1184:7
#12 0x00007f01f2ba1c51 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::StmtPrinter, void>::Visit(clang::Stmt*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/StmtNodes.inc:1127:1
#13 0x00007f01f2ba0977 (anonymous namespace)::StmtPrinter::Visit(clang::Stmt*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:151:5
#14 0x00007f01f2badb40 (anonymous namespace)::StmtPrinter::PrintExpr(clang::Expr*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:136:9
#15 0x00007f01f2ba89bd (anonymous namespace)::StmtPrinter::VisitImplicitCastExpr(clang::ImplicitCastExpr*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:1642:1
#16 0x00007f01f2ba1b9d clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::StmtPrinter, void>::Visit(clang::Stmt*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/StmtNodes.inc:1055:1
#17 0x00007f01f2ba0977 (anonymous namespace)::StmtPrinter::Visit(clang::Stmt*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:151:5
#18 0x00007f01f2ba086b clang::Stmt::printPretty(llvm::raw_ostream&, clang::PrinterHelper*, clang::PrintingPolicy const&, unsigned int, llvm::StringRef, clang::ASTContext const*) const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/StmtPrinter.cpp:2764:1
#19 0x00007f01f2bc9c26 clang::TemplateArgument::print(clang::PrintingPolicy const&, llvm::raw_ostream&, bool) const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/TemplateBase.cpp:462:5
#20 0x00007f01f2c5d424 printArgument(clang::TemplateArgument const&, clang::PrintingPolicy const&, llvm::raw_ostream&, bool) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/TypePrinter.cpp:2011:1
#21 0x00007f01f2c53791 void printTo<clang::TemplateArgument>(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, clang::TemplateParameterList const*, bool, unsigned int) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/TypePrinter.cpp:2226:33
#22 0x00007f01f2c533af clang::printTemplateArgumentList(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgument>, clang::PrintingPolicy const&, clang::TemplateParameterList const*) /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/TypePrinter.cpp:2267:1
#23 0x00007f01f2ad5576 clang::NestedNameSpecifier::print(llvm::raw_ostream&, clang::PrintingPolicy const&, bool) const /home/xxxxx/Sources/llvm-project-main/clang/lib/AST/NestedNameSpecifier.cpp:320:5
#24 0x00007f01e8a86268 printQualifier(llvm::raw_ostream&, clang::ASTContext&, clang::NestedNameSpecifier*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:639:1
#25 0x00007f01e8a8549b (anonymous namespace)::USRGenerator::VisitType(clang::QualType) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:912:7
#26 0x00007f01e8a8616f (anonymous namespace)::USRGenerator::VisitTemplateArgument(clang::TemplateArgument const&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:1030:5
#27 0x00007f01e8a85405 (anonymous namespace)::USRGenerator::VisitType(clang::QualType) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:906:28
#28 0x00007f01e8a88053 (anonymous namespace)::USRGenerator::VisitFunctionDecl(clang::FunctionDecl const*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:269:17
#29 0x00007f01e8a8825d clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::USRGenerator, void>::VisitCXXMethodDecl(clang::CXXMethodDecl const*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/DeclNodes.inc:443:1
#30 0x00007f01e8a7f711 clang::declvisitor::Base<llvm::make_const_ptr, (anonymous namespace)::USRGenerator, void>::Visit(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/build/tools/clang/include/clang/AST/DeclNodes.inc:443:1
#31 0x00007f01e8a7f221 clang::index::generateUSRForDecl(clang::Decl const*, llvm::SmallVectorImpl<char>&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Index/USRGeneration.cpp:1160:13
#32 0x00007f01f4e8c670 clang::cross_tu::CrossTranslationUnitContext::getLookupName[abi:cxx11](clang::NamedDecl const*) /home/xxxxx/Sources/llvm-project-main/clang/lib/CrossTU/CrossTranslationUnit.cpp:247:8
#33 0x0000555bf8e2030e MapExtDefNamesConsumer::addIfInMain(clang::DeclaratorDecl const*, clang::SourceLocation) /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:89:8
#34 0x0000555bf8e20172 MapExtDefNamesConsumer::handleDecl(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:72:23
#35 0x0000555bf8e202ba MapExtDefNamesConsumer::handleDecl(clang::Decl const*) /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:81:24
#36 0x0000555bf8e24d5d MapExtDefNamesConsumer::HandleTranslationUnit(clang::ASTContext&) /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:54:3
#37 0x00007f01e70eb253 clang::ParseAST(clang::Sema&, bool, bool) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseAST.cpp:183:12
#38 0x00007f01f3b8d281 clang::ASTFrontendAction::ExecuteAction() /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/FrontendAction.cpp:1186:1
#39 0x00007f01f3b8cc7c clang::FrontendAction::Execute() /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/FrontendAction.cpp:1074:7
#40 0x00007f01f3a88968 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/CompilerInstance.cpp:1054:23
#41 0x00007f01f3fe5983 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:467:14
#42 0x00007f01f3fe5821 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:442:18
#43 0x00007f01f3fe48bd clang::tooling::ToolInvocation::run() /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:427:3
#44 0x00007f01f3fe6b1e clang::tooling::ClangTool::run(clang::tooling::ToolAction*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:619:11
#45 0x0000555bf8e20ac6 HandleFiles(llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, clang::tooling::CompilationDatabase&) /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:193:5
#46 0x0000555bf8e208af main /home/xxxxx/Sources/llvm-project-main/clang/tools/clang-extdef-mapping/ClangExtDefMapGen.cpp:222:3
#47 0x00007f01f08461ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#48 0x00007f01f0846285 call_init ./csu/../csu/libc-start.c:128:20
#49 0x00007f01f0846285 __libc_start_main ./csu/../csu/libc-start.c:347:5
#50 0x0000555bf8e20001 _start (/home/xxxxx/Sources/llvm-project-main/build/bin/clang-extdef-mapping+0x18001)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/xxxxx/Sources/llvm-project-main/build/bin/clang-extdef-mapping test.cpp --
1.      <eof> parser at end of file
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkW19z4ygS_zTkhYoLgf4-5MGx492pmtnLJZ6tfXMhgW1uJKQSaNb59lcg2xLY-TvJ7O1eKjVjg9T079dN0zSEKiU2kvMrEF2DaH5BO72t2ytGpdilCF3kNXu4WnKlC6o4IFOA5gBNQYz632L_HS8AXkDNlZ4UTbNvtP9qXjUl1RwCMsvruoQzgGdQPzRc0orDJSA3_YNKt12hYVFLBkFy3TdC-yTja7iEywdA9s0gmQ-fT4Y5Cl8N0ouSKgW_vOStJcCzw-iHn2PnVwjI3O91njAAAJktDVlkem_QCqmNIrbBoHB0unuZTu5L12OKvteCwTXA6R0gs6KWShugM_sOuYG03QCcvZa7YUQr_voo0IB4bjCrXTL3nGU85l0n4Z9Cb6FxopLKzSXfacbXlxVtGiE3gy_FyFBYtFRtIeuq5tQJj8ScSAFkCgFebOuKA7zYmR-AF_d11xZcAbwoy-_VZdPW_-GFvqyokAAvrBzTJ3KAF9P7JcCL37jSnP1GK37f8EKsBW-tbmRKUGYGsRz1b1qCzrzQdzStcQacmpH7lpb-uaqVbjmtIMCxBWtpHYm7NW8JubmtS1E8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