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

    <tr>
        <th>Summary</th>
        <td>
            SemaDecl Assertion "Scope shouldn't contain decls!" failed
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            crash-on-invalid
      </td>
    </tr>

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

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

<pre>
    I happened to notice this while looking at an unrelated LLVM failure.

The following case compiles successfully:

```
// ================================================================
#include <utility>
struct c {
  void d() noexcept(std::is_nothrow_swappable_v< int > &&
                    std::is_nothrow_swappable_v< int >);
};
// ----------------------------------------------------------------
```

However if I remove the include statement then as well as some genuine-looking errors, I also get an assertion failure:

https://godbolt.org/z/b7orMY3jM

```
// ================================================================
//#include <utility>
struct c {
  void d() noexcept(std::is_nothrow_swappable_v< int > &&
                    std::is_nothrow_swappable_v< int >);
};
// ----------------------------------------------------------------
```

```
<source>:4:21: error: use of undeclared identifier 'std'
    4 |   void d() noexcept(std::is_nothrow_swappable_v< int > &&
      | ^
<source>:4:54: error: expected '(' for function-style cast or type construction
    4 |   void d() noexcept(std::is_nothrow_swappable_v< int > &&
      |                                                  ~~~ ^
<source>:5:24: error: expected ')'
    5 | std::is_nothrow_swappable_v< int >);
      | ^
<source>:4:20: note: to match this '('
    4 |   void d() noexcept(std::is_nothrow_swappable_v< int > &&
      | ^
clang-22: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaDecl.cpp:2241: void clang::Sema::ActOnPopScope(clang::SourceLocation, clang::Scope*): Assertion `(S->getFlags() & (Scope::DeclScope | Scope::TemplateParamScope)) && "Scope shouldn't contain decls!"' 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-20250811/bin/clang-22 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20250811/lib/clang/22 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0 -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/x86_64-linux-gnu -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.0.0/../../../../include/c++/16.0.0/backward -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20250811/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/16.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 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-19df18.o -x c++ <source>
1.      <source>:6:2: current parser token ';'
2.      <source>:3:1: parsing struct/union/class body 'c'
 #0 0x000000000400b248 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x400b248)
 #1 0x00000000040080f4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007209a6842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007209a68969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007209a6842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007209a68287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007209a682871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007209a6839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000006a61cc9 clang::Sema::ActOnPopScope(clang::SourceLocation, clang::Scope*) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x6a61cc9)
 #9 0x00000000066ad735 clang::Parser::ExitScope() (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66ad735)
#10 0x00000000066d50d8 clang::Parser::ParseLexedMethodDeclaration(clang::Parser::LateParsedMethodDeclaration&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66d50d8)
#11 0x00000000066ca8fd clang::Parser::ParseLexedMethodDeclarations(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66ca8fd)
#12 0x000000000671dff2 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x671dff2)
#13 0x0000000006720df0 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x6720df0)
#14 0x00000000066f413e clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66f413e)
#15 0x00000000066af698 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66af698)
#16 0x00000000066b00cf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66b00cf)
#17 0x00000000066b78a3 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66b78a3)
#18 0x00000000066b87b5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66b87b5)
#19 0x00000000066b8c70 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66b8c70)
#20 0x00000000066aa983 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x66aa983)
#21 0x00000000049b0c98 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x49b0c98)
#22 0x0000000004ca50a5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x4ca50a5)
#23 0x0000000004c213be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x4c213be)
#24 0x0000000004d967f1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0x4d967f1)
#25 0x0000000000daf0bf cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0xdaf0bf)
#26 0x0000000000da5d6a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000000000daa402 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0xdaa402)
#28 0x0000000000c5f604 main (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0xc5f604)
#29 0x00007209a6829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007209a6829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000000000da5815 _start (/opt/compiler-explorer/clang-assertions-trunk-20250811/bin/clang-22+0xda5815)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 254
```



</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWk1z4zbS_jX0BQUVCVIfPPigkazE9Xoqrngqb_akAoEmhRgEuABoy3vIb98CSJmSLGvHk2gqm1qVZkxSQOPppxvdDRDUWlEpgOto_CkaL69o6zbaXFcGqgL4M0h5VWj-cn2LNrRpQAFHTiOlnWCA3EZY9LwREpDU-lGoClGHqEKtMiCpA47u7n75jEoqZGtgFMXzKJ5_2QAqtZT62Xdg1AJium6EBItsyxhYW7ZSvkTpvOsQTeL-G88jsorICkXp8r_76zVJhWKy5YCidNE6IYV7idKbKJ5bZ1rmEEPR9FMUzxF60oIjHpFZRHKkNGwZNC4iM-u4ZymdC7tW2m2Mfl7bZ9o0tJCwforSBRLKoSi9QRGZ-K-X9vbz9XIikkepBxVNl_1FZxH8B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