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

    <tr>
        <th>Summary</th>
        <td>
            Segmentation fault in parser with bad class declaration
        </td>
    </tr>

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

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

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

<pre>
    When copying around some code I got a crash from a segfault in the parser.
The code is not correct and the issue I believe stems from putting other code between the closing bracket and semicolon of a class.

A minimal example is

```

template <class T> class Foo {
} void func() {
}

Foo() {}

Foo func2() {
  Foo vs;
  return vs;
}

int main() {}
```

The compile command was `clang++ -Wall -o basic del.cpp`

The compile version was 
```
clang++ --version
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 51297a7a720c83f831b072df4666877673f87cfa)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wheatman/llvm-project/build/bin
```

The back-trace  is 

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: /home/wheatman/llvm-project/build/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name del.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 -fcoverage-compilation-dir=/home/wheatman/MultiEdgeMapVertexMap/CSR -resource-dir /home/wheatman/llvm-project/build/lib/clang/17 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/backward -internal-isystem /home/wheatman/llvm-project/build/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -fdeprecated-macro -fdebug-compilation-dir=/home/wheatman/MultiEdgeMapVertexMap/CSR -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/del-458e89.o -x c++ del.cpp
1.      del.cpp:9:9: current parser token ';'
2.      del.cpp:8:13: parsing function body 'func2'
3. del.cpp:8:13: in compound statement ('{}')
 #0 0x0000564635651787 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/wheatman/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x000056463564fac0 llvm::sys::RunSignalHandlers() /home/wheatman/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x0000564635651e2a SignalHandler(int) /home/wheatman/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007fe2619a9520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000564637655c4e clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) /home/wheatman/llvm-project/clang/lib/Sema/SemaInit.cpp:8418:23
 #5 0x000056463738afef clang::Sema::ActOnUninitializedDecl(clang::Decl*) /home/wheatman/llvm-project/clang/lib/Sema/SemaDecl.cpp:13843:31
 #6 0x000056463718a0ec clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /home/wheatman/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:13
 #7 0x000056463718882c clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/wheatman/llvm-project/clang/lib/Parse/ParseDecl.cpp:2235:21
 #8 0x0000564637187da5 clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) /home/wheatman/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:10
 #9 0x0000564637187942 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /home/wheatman/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:0
#10 0x0000564637213582 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) /home/wheatman/llvm-project/clang/lib/Parse/ParseStmt.cpp:248:16
#11 0x0000564637211a26 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /home/wheatman/llvm-project/clang/lib/Parse/ParseStmt.cpp:116:20
#12 0x0000564637219c2f clang::Parser::ParseCompoundStatementBody(bool) /home/wheatman/llvm-project/clang/lib/Parse/ParseStmt.cpp:1186:11
#13 0x000056463721acaa clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /home/wheatman/llvm-project/clang/lib/Parse/ParseStmt.cpp:2450:21
#14 0x00005646371726e2 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /home/wheatman/llvm-project/clang/lib/Parse/Parser.cpp:0:0
#15 0x0000564637189559 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/wheatman/llvm-project/clang/lib/Parse/ParseDecl.cpp:2175:18
#16 0x000056463717156b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /home/wheatman/llvm-project/clang/lib/Parse/Parser.cpp:0:10
#17 0x0000564637170fa0 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /home/wheatman/llvm-project/clang/lib/Parse/Parser.cpp:1228:12
#18 0x00005646371702aa clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /home/wheatman/llvm-project/clang/lib/Parse/Parser.cpp:0:14
#19 0x000056463716e41f clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/wheatman/llvm-project/clang/lib/Parse/Parser.cpp:0:12
#20 0x000056463716a62e clang::ParseAST(clang::Sema&, bool, bool) /home/wheatman/llvm-project/clang/lib/Parse/ParseAST.cpp:161:5
#21 0x0000564635dbdcc8 clang::FrontendAction::Execute() /home/wheatman/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1060:10
#22 0x0000564635d3a156 llvm::Error::getPtr() const /home/wheatman/llvm-project/llvm/include/llvm/Support/Error.h:275:12
#23 0x0000564635d3a156 llvm::Error::operator bool() /home/wheatman/llvm-project/llvm/include/llvm/Support/Error.h:235:16
#24 0x0000564635d3a156 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/wheatman/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1049:23
#25 0x0000564635e6c5a1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/wheatman/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:264:25
#26 0x0000564633a80aa5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/wheatman/llvm-project/clang/tools/driver/cc1_main.cpp:251:15
#27 0x0000564633a7dc10 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/wheatman/llvm-project/clang/tools/driver/driver.cpp:366:12
#28 0x0000564633a7ccb4 clang_main(int, char**, llvm::ToolContext const&) /home/wheatman/llvm-project/clang/tools/driver/driver.cpp:407:12
#29 0x0000564633a8a331 main /home/wheatman/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:15:3
#30 0x00007fe261990d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x00007fe261990e40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007fe261990e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x0000564633a7a495 _start (/home/wheatman/llvm-project/build/bin/clang-17+0xd8f495)
clang++: error: unable to execute command: Segmentation fault
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 51297a7a720c83f831b072df4666877673f87cfa)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/wheatman/llvm-project/build/bin
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/del-f99a92.cpp
clang++: note: diagnostic msg: /tmp/del-f99a92.sh
clang++: note: diagnostic msg: 

********************
  


The requested files are 
[del-f99a92.sh.txt](https://github.com/llvm/llvm-project/files/11346290/del-f99a92.sh.txt)
[del-f99a92.cpp.txt](https://github.com/llvm/llvm-project/files/11346289/del-f99a92.cpp.txt)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWlt3o7iT_zTkRQcfEObihzw4cdyds-lNtp2ZfswRosD6N0iMJBJnP_0eCbCBONdOz87DzOmxHSFKVb-6SiqiFCs4wKkTnjnh6oQ0eivk6cMWi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