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

    <tr>
        <th>Summary</th>
        <td>
            [clang] [Modules] Assertion failure when naming a function `make_integer_sequence`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Given the following valid translation units:

```c++
export module a;

namespace n {

template<typename, int...>
struct integer_sequence;

template<typename>
using make_integer_sequence = __make_integer_seq<integer_sequence, int, 0>;

} // namespace

export void make_integer_sequence();
```

```c++
export module b;

import a;

template<typename T>
void b() {
        f(make_integer_sequence<T>());
}
```

clang crashes with

```console
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot   -fcolor-diagnostics -fno-crash-diagnostics -std=c++23 -MD -MT CMakeFiles/bug.dir/b.cpp.o -MF CMakeFiles/bug.dir/b.cpp.o.d @CMakeFiles/bug.dir/b.cpp.o.modmap -o CMakeFiles/bug.dir/b.cpp.o -c /app/b.cpp
clang-20: /root/llvm-project/clang/lib/Serialization/ASTWriter.cpp:6285: bool clang::ASTWriter::wasDeclEmitted(const clang::Decl*) const: Assertion `(Emitted || (!D->getOwningModule() && isWritingStdCXXNamedModules()) || GeneratingReducedBMI) && "The declaration within modules can only be omitted in reduced BMI."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-module-interface -disable-free -clear-ast-before-backend -main-file-name b.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/app/build -fcoverage-compilation-dir=/app/build -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20240809/lib/clang/20 -dependency-file CMakeFiles/bug.dir/b.cpp.o.d -MT CMakeFiles/bug.dir/b.cpp.o -sys-header-deps -module-file-deps -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../include/c++/15.0.0/backward -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20240809/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++23 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=a=CMakeFiles/bug.dir/a.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/bug.dir/b.pcm -x c++ /app/b.cpp
1.      <eof> parser at end of file
 #0 0x0000000003abb448 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x3abb448)
 #1 0x0000000003ab8bbc SignalHandler(int) Signals.cpp:0:0
 #2 0x00007ff09e442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007ff09e4969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007ff09e442476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007ff09e4287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007ff09e42871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007ff09e439e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000048450ae clang::ASTWriter::wasDeclEmitted(clang::Decl const*) const (.part.0) ASTWriter.cpp:0:0
 #9 0x0000000004898d99 clang::ASTWriter::WriteDeclAndTypes(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x4898d99)
#10 0x0000000004899f40 clang::ASTWriter::WriteASTCore(clang::Sema&, llvm::StringRef, clang::Module*) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x4899f40)
#11 0x000000000489ae4a clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, llvm::StringRef, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x489ae4a)
#12 0x00000000048c1289 clang::PCHGenerator::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x48c1289)
#13 0x00000000048c1351 clang::CXX20ModulesGenerator::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x48c1351)
#14 0x00000000046939b8 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x46939b8)
#15 0x00000000064c73bc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x64c73bc)
#16 0x0000000004659819 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x4659819)
#17 0x00000000045dde2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x45dde2e)
#18 0x0000000004742cee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0x4742cee)
#19 0x0000000000c926af cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0xc926af)
#20 0x0000000000c8b83a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000000000c8f16e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0xc8f16e)
#22 0x0000000000b63644 main (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0xb63644)
#23 0x00007ff09e429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#24 0x00007ff09e429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#25 0x0000000000c8b2ee _start (/opt/compiler-explorer/clang-assertions-trunk-20240809/bin/clang-20+0xc8b2ee)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
```

See it live: https://godbolt.org/z/M9KoKvo8T

Note that `module a` is equivalent to

```c++
module;

#include <utility>

export module a;

export void make_integer_sequence();
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWlFz4zYO_jXMC4cemZJl6SEPXjtud3rp7TS5dt88FAXJvFCkSlKO019_Q0p2LMdNNr3mbjtp1qZI4PtAAASFMGtFrQCu0ewTmq2uWOe22lyXbCdK67SCq0KXT9c_iB0o7LaAKy2lfhSqxjsmRYmdYcpK5oRWuFPCWRQvULRC0eF3GvU_HNFP_ieMwr7VxuFGl50EzFD86XSNYg3YlnHACqP56JGDppXMAYqX7qkFPxPRJRbKTSYTFN_0s6wzHXd-FGowGwu_d6A4nKm5JOsgobOeYsMeYHMuBaN4hTeb82coX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