<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 - ICE on invalid: SemaTemplateInstantiate.cpp "Cannot perform an instantiation without some context on the instantiation stack""
   href="https://bugs.llvm.org/show_bug.cgi?id=49734">49734</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>ICE on invalid: SemaTemplateInstantiate.cpp "Cannot perform an instantiation without some context on the instantiation stack"
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Assertion failed while cross compiling on macOS for Linux [Assertion failed: (!CodeSynthesisContexts.empty() && "Cannot perform an instantiation without some context on the " "instantiation stack")]"
   href="show_bug.cgi?id=36735">Bug 36735</a> (from two years ago) is possibly related.

cat >test.cpp <<EOF
template struct
struct a<b[>; c typename }}}}
template<class,class=> struct d : ;
template<class e> struct d<e,decltype(f<int(e)>())>
public
EOF
clang++ -std=c++11 -w -c test.cpp


Notice that SOME of the newlines in the input are SIGNIFICANT! (Yikes!)
Also notice that you must use a Debug build to reproduce, because the symptom
is an assertion failure.

======

test.cpp:1:16: error: expected ';' after struct
template struct
               ^
               ;
test.cpp:1:10: error: declaration of anonymous struct must be a definition
template struct
         ^
test.cpp:1:10: error: declaration does not declare anything
test.cpp:2:10: error: use of undeclared identifier 'b'
struct a<b[>; c typename }}}}
         ^
test.cpp:2:12: error: expected expression
struct a<b[>; c typename }}}}
           ^
test.cpp:2:13: error: expected expression
struct a<b[>; c typename }}}}
            ^
test.cpp:2:13: error: expected ']'
test.cpp:2:11: note: to match this '['
struct a<b[>; c typename }}}}
          ^
test.cpp:2:13: error: expected '>'
struct a<b[>; c typename }}}}
            ^
test.cpp:2:9: note: to match this '<'
struct a<b[>; c typename }}}}
        ^
test.cpp:2:8: error: explicit specialization of non-template struct 'a'
struct a<b[>; c typename }}}}
       ^
test.cpp:2:15: error: unknown type name 'c'
struct a<b[>; c typename }}}}
              ^
test.cpp:2:26: error: expected a qualified name after 'typename'
struct a<b[>; c typename }}}}
                         ^
test.cpp:2:26: error: expected unqualified-id
test.cpp:2:26: error: extraneous closing brace ('}')
test.cpp:2:27: error: extraneous closing brace ('}')
struct a<b[>; c typename }}}}
                          ^
test.cpp:2:28: error: extraneous closing brace ('}')
struct a<b[>; c typename }}}}
                           ^
test.cpp:2:29: error: extraneous closing brace ('}')
struct a<b[>; c typename }}}}
                            ^
test.cpp:3:22: error: expected a type
template<class,class=> struct d : ;
                     ^
test.cpp:3:35: error: expected class name
template<class,class=> struct d : ;
                                  ^
test.cpp:3:34: error: expected '{' after base class list
template<class,class=> struct d : ;
                                 ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Assertion failed: (!CodeSynthesisContexts.empty() && "Cannot perform an
instantiation without some context on the " "instantiation stack"), function
SubstType, file
/Users/aodwyer/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp, line
2071.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /Users/aodwyer/llvm-project/build-debug/bin/clang++
-std=c++11 -w -c test.cpp
1.      test.cpp:5:1: current parser token 'public'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang++                  0x00000001086da63d
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61
1  clang++                  0x00000001086dabbb
PrintStackTraceSignalHandler(void*) + 27
2  clang++                  0x00000001086d8b13 llvm::sys::RunSignalHandlers() +
115
3  clang++                  0x00000001086d9ede
llvm::sys::CleanupOnSignal(unsigned long) + 110
4  clang++                  0x0000000108578b20 (anonymous
namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 192
5  clang++                  0x0000000108578e73 CrashRecoverySignalHandler(int)
+ 195
6  libsystem_platform.dylib 0x00007fff697a5b5d _sigtramp + 29
7  libsystem_platform.dylib 0x00007fd74e83f700 _sigtramp + 18446743901458504640
8  libsystem_c.dylib        0x00007fff6965f6a6 abort + 127
9  libsystem_c.dylib        0x00007fff6962820d basename_r + 0
10 clang++                  0x000000010d104f31
clang::Sema::SubstType(clang::TypeSourceInfo*,
clang::MultiLevelTemplateArgumentList const&, clang::SourceLocation,
clang::DeclarationName, bool) + 145
11 clang++                  0x000000010d108445
clang::Sema::SubstParmVarDecl(clang::ParmVarDecl*,
clang::MultiLevelTemplateArgumentList const&, int, llvm::Optional<unsigned
int>, bool) + 741
12 clang++                  0x000000010d15106f (anonymous
namespace)::TemplateInstantiator::TransformFunctionTypeParam(clang::ParmVarDecl*,
int, llvm::Optional<unsigned int>, bool) + 79
13 clang++                  0x000000010d109dad clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionTypeParams(clang::SourceLocation,
llvm::ArrayRef<clang::ParmVarDecl*>, clang::QualType const*,
clang::FunctionType::ExtParameterInfo const*,
llvm::SmallVectorImpl<clang::QualType>&,
llvm::SmallVectorImpl<clang::ParmVarDecl*>*,
clang::Sema::ExtParameterInfoBuilder&) + 2173
14 clang++                  0x000000010d14e32a clang::QualType
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionProtoType<clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionProtoType(clang::TypeLocBuilder&,
clang::FunctionProtoTypeLoc)::'lambda'(clang::FunctionProtoType::ExceptionSpecInfo&,
bool&)>(clang::TypeLocBuilder&, clang::FunctionProtoTypeLoc,
clang::CXXRecordDecl*, clang::Qualifiers, clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionProtoType(clang::TypeLocBuilder&,
clang::FunctionProtoTypeLoc)::'lambda'(clang::FunctionProtoType::ExceptionSpecInfo&,
bool&)) + 1050
15 clang++                  0x000000010d14debe clang::QualType (anonymous
namespace)::TemplateInstantiator::TransformFunctionProtoType<clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionProtoType(clang::TypeLocBuilder&,
clang::FunctionProtoTypeLoc)::'lambda'(clang::FunctionProtoType::ExceptionSpecInfo&,
bool&)>(clang::TypeLocBuilder&, clang::FunctionProtoTypeLoc,
clang::CXXRecordDecl*, clang::Qualifiers, (anonymous
namespace)::TemplateInstantiator) + 270
16 clang++                  0x000000010d14dd5d clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformFunctionProtoType(clang::TypeLocBuilder&,
clang::FunctionProtoTypeLoc) + 237
17 clang++                  0x000000010d146e3d (anonymous
namespace)::TemplateInstantiator::TransformFunctionProtoType(clang::TypeLocBuilder&,
clang::FunctionProtoTypeLoc) + 61
18 clang++                  0x000000010d106354 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&,
clang::TypeLoc) + 2388
19 clang++                  0x000000010d1055b2 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) + 354
20 clang++                  0x000000010d134f17 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc
const&, clang::TemplateArgumentLoc&, bool) + 1079
21 clang++                  0x000000010d11168c bool
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArguments<clang::TemplateArgumentLoc
const*>(clang::TemplateArgumentLoc const*, clang::TemplateArgumentLoc const*,
clang::TemplateArgumentListInfo&, bool) + 2428
22 clang++                  0x000000010d115de7 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArguments(clang::TemplateArgumentLoc
const*, unsigned int, clang::TemplateArgumentListInfo&, bool) + 71
23 clang++                  0x000000010d12c3a7 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformUnresolvedLookupExpr(clang::UnresolvedLookupExpr*)
+ 1159
24 clang++                  0x000000010d112c82 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) + 5490
25 clang++                  0x000000010d124980 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformCallExpr(clang::CallExpr*) + 80
26 clang++                  0x000000010d111faf clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) + 2207
27 clang++                  0x000000010d1447d4 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformDecltypeType(clang::TypeLocBuilder&,
clang::DecltypeTypeLoc) + 132
28 clang++                  0x000000010d105ee0 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeLocBuilder&,
clang::TypeLoc) + 1248
29 clang++                  0x000000010d1055b2 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformType(clang::TypeSourceInfo*) + 354
30 clang++                  0x000000010d134f17 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArgument(clang::TemplateArgumentLoc
const&, clang::TemplateArgumentLoc&, bool) + 1079
31 clang++                  0x000000010d11168c bool
clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArguments<clang::TemplateArgumentLoc
const*>(clang::TemplateArgumentLoc const*, clang::TemplateArgumentLoc const*,
clang::TemplateArgumentListInfo&, bool) + 2428
32 clang++                  0x000000010d115de7 clang::TreeTransform<(anonymous
namespace)::TemplateInstantiator>::TransformTemplateArguments(clang::TemplateArgumentLoc
const*, unsigned int, clang::TemplateArgumentListInfo&, bool) + 71
33 clang++                  0x000000010d108efb
clang::Sema::Subst(clang::TemplateArgumentLoc const*, unsigned int,
clang::TemplateArgumentListInfo&, clang::MultiLevelTemplateArgumentList const&)
+ 139
34 clang++                  0x000000010d0f7689
std::__1::enable_if<IsPartialSpecialization<clang::ClassTemplatePartialSpecializationDecl>::value,
clang::Sema::TemplateDeductionResult>::type
FinishTemplateArgumentDeduction<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::ClassTemplatePartialSpecializationDecl*, bool,
clang::TemplateArgumentList const&,
llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&,
clang::sema::TemplateDeductionInfo&) + 633
35 clang++                  0x000000010d0fe610 bool
isAtLeastAsSpecializedAs<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::QualType, clang::QualType,
clang::ClassTemplatePartialSpecializationDecl*,
clang::sema::TemplateDeductionInfo&)::'lambda'()::operator()() const + 112
36 clang++                  0x000000010d0fe595 void llvm::function_ref<void
()>::callback_fn<bool
isAtLeastAsSpecializedAs<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::QualType, clang::QualType,
clang::ClassTemplatePartialSpecializationDecl*,
clang::sema::TemplateDeductionInfo&)::'lambda'()>(long) + 21
37 clang++                  0x00000001085789b9 llvm::function_ref<void
()>::operator()() const + 25
38 clang++                  0x000000010c12ae2d
clang::runWithSufficientStackSpace(llvm::function_ref<void ()>,
llvm::function_ref<void ()>) + 109
39 clang++                  0x000000010c12adb0
clang::Sema::runWithSufficientStackSpace(clang::SourceLocation,
llvm::function_ref<void ()>) + 96
40 clang++                  0x000000010d01f7b4 bool
isAtLeastAsSpecializedAs<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::QualType, clang::QualType,
clang::ClassTemplatePartialSpecializationDecl*,
clang::sema::TemplateDeductionInfo&) + 708
41 clang++                  0x000000010d01f91a
clang::Sema::isMoreSpecializedThanPrimary(clang::ClassTemplatePartialSpecializationDecl*,
clang::sema::TemplateDeductionInfo&) + 234
42 clang++                  0x000000010cfc6ebd void
checkMoreSpecializedThanPrimary<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::ClassTemplatePartialSpecializationDecl*) + 141
43 clang++                  0x000000010cedb620 void
checkTemplatePartialSpecialization<clang::ClassTemplatePartialSpecializationDecl>(clang::Sema&,
clang::ClassTemplatePartialSpecializationDecl*) + 32
44 clang++                  0x000000010cedb5ed
clang::Sema::CheckTemplatePartialSpecialization(clang::ClassTemplatePartialSpecializationDecl*)
+ 29
45 clang++                  0x000000010cee9ea9
clang::Sema::ActOnClassTemplateSpecialization(clang::Scope*, unsigned int,
clang::Sema::TagUseKind, clang::SourceLocation, clang::SourceLocation,
clang::CXXScopeSpec&, clang::TemplateIdAnnotation&, clang::ParsedAttributesView
const&, llvm::MutableArrayRef<clang::TemplateParameterList*>,
clang::Sema::SkipBodyInfo*) + 5209
46 clang++                  0x000000010bf5f1c9
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext,
clang::Parser::ParsedAttributesWithRange&) + 7241
47 clang++                  0x000000010bf3e4c3
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) + 15395
48 clang++                  0x000000010c00af09
clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext,
clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 841
49 clang++                  0x000000010c00a242
clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) +
1426
50 clang++                  0x000000010c009b74
clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext,
clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) + 228
51 clang++                  0x000000010bf3a22b
clang::Parser::ParseDeclaration(clang::DeclaratorContext,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&,
clang::SourceLocation*) + 331
52 clang++                  0x000000010c01e19d
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) + 2397
53 clang++                  0x000000010c01c6bb
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool)
+ 1739
54 clang++                  0x000000010bf295e4 clang::ParseAST(clang::Sema&,
bool, bool) + 580
55 clang++                  0x000000010976fe8c
clang::ASTFrontendAction::ExecuteAction() + 300
56 clang++                  0x00000001090a855a
clang::CodeGenAction::ExecuteAction() + 90
57 clang++                  0x000000010976f4bc clang::FrontendAction::Execute()
+ 124
58 clang++                  0x00000001096892e8
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 920
59 clang++                  0x000000010987872e
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1614
60 clang++                  0x0000000104c3263d cc1_main(llvm::ArrayRef<char
const*>, char const*, void*) + 1501
61 clang++                  0x0000000104c24e3b
ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) + 427
62 clang++                  0x00000001094404c5
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__1::basic_string<char, std::__1::char_traits<char>,</span >
std::__1::allocator<char> >*, bool*) const::$_1::operator()() const + 37
63 clang++                  0x0000000109440495 void llvm::function_ref<void
()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__1::basic_string<char, std::__1::char_traits<char>,</span >
std::__1::allocator<char> >*, bool*) const::$_1>(long) + 21
64 clang++                  0x00000001085789b9 llvm::function_ref<void
()>::operator()() const + 25
65 clang++                  0x000000010857895c
llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 236
66 clang++                  0x000000010943ef5c
clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>
<span class="quote">>, std::__1::basic_string<char, std::__1::char_traits<char>,</span >
std::__1::allocator<char> >*, bool*) const + 524
67 clang++                  0x00000001093e9406
clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&,
clang::driver::Command const*&) const + 758
68 clang++                  0x00000001093e96c8
clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&,
llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&)
const + 152
69 clang++                  0x00000001094044f5
clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&,
llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) +
325
70 clang++                  0x0000000104c2438b main + 3371
71 libdyld.dylib            0x00007fff695ba3d5 start + 1
72 libdyld.dylib            0x0000000000000005 start + 18446603338748550193
clang-13: error: clang frontend command failed with exit code 134 (use -v to
see invocation)
clang version 13.0.0 (<a href="mailto:git@github.com">git@github.com</a>:Quuxplusone/llvm-project
4adea96d9486bb19440243420ba234c1916907c9)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Users/aodwyer/llvm-project/build-debug/bin
clang-13: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg:
/var/folders/0l/9t0yv2890_g4wgmy53n_mg7w0000gy/T/test-197322.cpp
clang-13: note: diagnostic msg:
/var/folders/0l/9t0yv2890_g4wgmy53n_mg7w0000gy/T/test-197322.sh
clang-13: note: diagnostic msg: Crash backtrace is located in
clang-13: note: diagnostic msg:
/Users/aodwyer/Library/Logs/DiagnosticReports/clang-13_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang-13: note: diagnostic msg: (choose the .crash file that corresponds to
your crash)
clang-13: note: diagnostic msg: 

********************</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>