<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Compiler crashes with some invalid templates"
   href="https://bugs.llvm.org/show_bug.cgi?id=39870">39870</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compiler crashes with some invalid templates
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++'17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>exyi@exyi.cz
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21190" name="attach_21190" title="The files clang told me to attach">attachment 21190</a> <a href="attachment.cgi?id=21190&action=edit" title="The files clang told me to attach">[details]</a></span>
The files clang told me to attach

When I try to compile using `clang++ database/test.cpp -std=c++17`
```
template<typename A> struct X { };
struct Y { X() { } };
```

it crashes. I know that the program is not valid, but the compiler
should not segfault on that.

This is the output of the compiler:

```
test.cpp:2:12: error: deduction guide must be declared in the same scope as
template 'X'
struct Y { X() { } };
           ^
test.cpp:1:29: note: template is declared here
template<typename A> struct X { };
                            ^
test.cpp:2:12: error: deduction guide declaration without trailing return type
struct Y { X() { } };
           ^
test.cpp:2:12: error: deduction guide cannot have a function definition
test.cpp:2:12: error: deduction guide has different access from the
corresponding member template
test.cpp:1:1: note: member template declared private here
template<typename A> struct X { };
^
Stack dump:
0.      Program arguments: /usr/bin/clang-7 -cc1 -triple x86_64-pc-linux-gnu
-emit-llvm-bc -emit-llvm-uselists -save-temps=cwd -disable-free
-disable-llvm-verifier -discard-value-names -main-file-name test.cpp
-mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix
-mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
-debugger-tuning=gdb -resource-dir /usr/lib/clang/7.0.0 -O0 -std=c++17
-fdeprecated-macro -fdebug-compilation-dir /home/exyi/skola/c++/database
-ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -disable-llvm-passes -o
test.bc -x c++-cpp-output test.ii -faddrsig 
1.      test.cpp:2:16: current parser token '{'
2.      test.cpp:2:1: parsing struct/union/class body 'Y'
#0 0x00007f92b7fb7b1b llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/usr/bin/../lib/libLLVM-7.so+0x8feb1b)
#1 0x00007f92b7fb5f74 llvm::sys::RunSignalHandlers()
(/usr/bin/../lib/libLLVM-7.so+0x8fcf74)
#2 0x00007f92b7fb60fe (/usr/bin/../lib/libLLVM-7.so+0x8fd0fe)
#3 0x00007f92b68c3e00 __restore_rt (/usr/bin/../lib/libc.so.6+0x37e00)
#4 0x00007f92b55d7c4a clang::Sema::ActOnCXXMemberDeclarator(clang::Scope*,
clang::AccessSpecifier, clang::Declarator&,
llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Expr*,
clang::VirtSpecifiers const&, clang::InClassInitStyle)
(/usr/bin/../lib/../lib/libclangSema.so.7+0x2ffc4a)
#5 0x00007f92b5aa20d3
clang::Parser::ParseCXXInlineMethodDef(clang::AccessSpecifier,
clang::ParsedAttributes&, clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::VirtSpecifiers const&,
clang::SourceLocation) (/usr/bin/../lib/../lib/libclangParse.so.7+0x2f0d3)
#6 0x00007f92b5ad26ad
clang::Parser::ParseCXXClassMemberDeclaration(clang::AccessSpecifier,
clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo const&,
clang::ParsingDeclRAIIObject*)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x5f6ad)
#7 0x00007f92b5ad3fbf
clang::Parser::ParseCXXClassMemberDeclarationWithPragmas(clang::AccessSpecifier&,
clang::Parser::ParsedAttributesWithRange&, clang::TypeSpecifierType,
clang::Decl*) (/usr/bin/../lib/../lib/libclangParse.so.7+0x60fbf)
#8 0x00007f92b5ad4850
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation,
clang::SourceLocation, clang::Parser::ParsedAttributesWithRange&, unsigned int,
clang::Decl*) (/usr/bin/../lib/../lib/libclangParse.so.7+0x61850)
#9 0x00007f92b5ad7409 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x64409)
#10 0x00007f92b5ab51eb
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x421eb)
#11 0x00007f92b5b44b3a
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
(/usr/bin/../lib/../lib/libclangParse.so.7+0xd1b3a)
#12 0x00007f92b5b458a2 (/usr/bin/../lib/../lib/libclangParse.so.7+0xd28a2)
#13 0x00007f92b5b4b131
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) (/usr/bin/../lib/../lib/libclangParse.so.7+0xd8131)
#14 0x00007f92b5b4bd7a
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
(/usr/bin/../lib/../lib/libclangParse.so.7+0xd8d7a)
#15 0x00007f92b5a9d828 clang::ParseAST(clang::Sema&, bool, bool)
(/usr/bin/../lib/../lib/libclangParse.so.7+0x2a828)
#16 0x00007f92b71e9d38 clang::CodeGenAction::ExecuteAction()
(/usr/bin/../lib/libclangCodeGen.so.7+0x2cdd38)
#17 0x00007f92b6cc0856 clang::FrontendAction::Execute()
(/usr/bin/../lib/libclangFrontend.so.7+0xd7856)
#18 0x00007f92b6c7f559
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
(/usr/bin/../lib/libclangFrontend.so.7+0x96559)
#19 0x00007f92b6be599d
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
(/usr/bin/../lib/libclangFrontendTool.so.7+0x499d)
#20 0x00005594c12dac39 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*) (/usr/bin/clang-7+0x11c39)
#21 0x00005594c12d7946 main (/usr/bin/clang-7+0xe946)
#22 0x00007f92b68b0223 __libc_start_main (/usr/bin/../lib/libc.so.6+0x24223)
#23 0x00005594c12d85ae _start (/usr/bin/clang-7+0xf5ae)
clang-7: error: unable to execute command: Segmentation fault (core dumped)
clang-7: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-7: note: diagnostic msg: PLEASE submit a bug report to  and include the
crash backtrace, preprocessed source, and associated run script.
clang-7: note: diagnostic msg: 
********************

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

********************
```

The `.ii` file and crash reporter files are in the attached zip.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>