[CTAD] Generated implicit deduction guides fails for inner / nested class when ctor has ref to outer class
The generated implicit deduction guide is invalid for nested (inner) class template where:
- C++20+ standard is used.
- outer class is also class template.
- constructor matching invocation contains reference to outer class as parameter (in short form).
Sample:
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc: -std:c++20 -W4 -O2
#include <functional>
template <typename T>
struct A
{
template <typename U>
struct B
{
B(A& a, U& b)
: m_a(std::ref(a)), m_b(std::ref(b))
{}
std::reference_wrapper<A> m_a;
std::reference_wrapper<U> m_b;
};
// Generated implicit deduction is invalid and in more
// complicated scenarios causes compiler to crash.
// The implicit guide is correctly generated on
// msvc and gcc.
//
// If you uncomment this explicit guide it will work:
// template <typename U> B(A&, U&) -> B<U>;
void fun()
{
int a = 1;
B b1{*this, a};
}
};
int main()
{
A<long> a;
a.fun();
}
For more sophisticated deduction the invalid CTAD / generated deduction guide can cause compiler crash (SIGSEGV on Linux, Access Violation on Windows (clang-cl)).
@llvm/issue-subscribers-c-20
Author: Marcin Walkowiak (666kod666)
Sample:
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc: -std:c++20 -W4 -O2
#include <functional>
template <typename T>
struct A
{
template <typename U>
struct B
{
B(A& a, U& b)
: m_a(std::ref(a)), m_b(std::ref(b))
{}
std::reference_wrapper<A> m_a;
std::reference_wrapper<U> m_b;
};
// Generated implicit deduction is invalid and in more
// complicated scenarios causes compiler to crash.
// The implicit guide is correctly generated on
// msvc and gcc.
//
// If you uncomment this explicit guide it will work:
// template <typename U> B(A&, U&) -> B<U>;
void fun()
{
int a = 1;
B b1{*this, a};
}
};
int main()
{
A<long> a;
a.fun();
}
For more sophisticated deduction the invalid CTAD / generated deduction guide can cause compiler crash (SIGSEGV on Linux, Access Violation on Windows (clang-cl)).
@llvm/issue-subscribers-clang-frontend
Author: Marcin Walkowiak (666kod666)
Sample:
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc: -std:c++20 -W4 -O2
#include <functional>
template <typename T>
struct A
{
template <typename U>
struct B
{
B(A& a, U& b)
: m_a(std::ref(a)), m_b(std::ref(b))
{}
std::reference_wrapper<A> m_a;
std::reference_wrapper<U> m_b;
};
// Generated implicit deduction is invalid and in more
// complicated scenarios causes compiler to crash.
// The implicit guide is correctly generated on
// msvc and gcc.
//
// If you uncomment this explicit guide it will work:
// template <typename U> B(A&, U&) -> B<U>;
void fun()
{
int a = 1;
B b1{*this, a};
}
};
int main()
{
A<long> a;
a.fun();
}
For more sophisticated deduction the invalid CTAD / generated deduction guide can cause compiler crash (SIGSEGV on Linux, Access Violation on Windows (clang-cl)).
The sample that causes compiler to crash (requires boost headers + C++20):
#include <boost/container/deque.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/copy.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/iterator/iterator_categories.hpp>
#include <concepts>
#include <functional>
#include <type_traits>
#include <variant>
#include <vector>
template <typename GraphTy, typename NodeIdTy = std::size_t>
concept bgl_graph =
requires(GraphTy g)
{
typename GraphTy::vertex_descriptor;
requires std::integral<typename GraphTy::vertex_descriptor> &&
std::convertible_to<NodeIdTy, typename GraphTy::vertex_descriptor> &&
std::convertible_to<typename GraphTy::vertex_descriptor, NodeIdTy>;
typename boost::graph_traits<GraphTy>::directed_category;
requires std::is_base_of_v<boost::bidirectional_tag, typename boost::graph_traits<GraphTy>::directed_category>;
typename boost::graph_traits<GraphTy>::out_edge_iterator;
requires std::random_access_iterator<typename boost::graph_traits<GraphTy>::out_edge_iterator> ||
std::is_convertible_v<boost::iterators::iterator_traversal_t<typename boost::graph_traits<GraphTy>::out_edge_iterator>,
boost::random_access_traversal_tag>;
typename boost::graph_traits<GraphTy>::edge_parallel_category;
requires std::is_base_of_v<boost::allow_parallel_edge_tag,
typename boost::graph_traits<GraphTy>::edge_parallel_category>;
};
template <typename GraphTy, typename NodeIdTy = std::size_t>
concept bgl_mutable_graph =
bgl_graph<GraphTy, NodeIdTy> &&
requires (GraphTy& g, const typename GraphTy::vertex_descriptor& n)
{
{ boost::add_vertex(g) } -> std::convertible_to<typename GraphTy::vertex_descriptor>;
boost::clear_vertex(n, g);
boost::remove_vertex(n, g);
{ boost::add_edge(n, n, g) }
-> std::convertible_to<std::pair<typename boost::graph_traits<GraphTy>::edge_descriptor, bool>>;
};
template <typename MGraphTy,
typename IGraphTy = MGraphTy,
std::integral NodeIdTy = std::size_t>
class sample_graph
{
constexpr static bool can_freeze_ = !std::same_as<std::remove_cvref_t<IGraphTy>, std::remove_cvref_t<MGraphTy>>;
using my_graph = std::conditional_t<can_freeze_, std::variant<MGraphTy, IGraphTy>, MGraphTy>;
template <typename FunTy>
requires std::invocable<FunTy, const MGraphTy&> &&
(!can_freeze_ || std::invocable<FunTy, const IGraphTy&>)
constexpr auto with_ro_graph(FunTy&& fun) const
noexcept(std::is_nothrow_invocable_v<FunTy, const MGraphTy&> &&
(!can_freeze_ || std::is_nothrow_invocable_v<FunTy, const IGraphTy&>))
-> std::conditional_t<can_freeze_,
std::common_type_t<std::invoke_result_t<FunTy, const MGraphTy&>,
std::invoke_result_t<FunTy, const IGraphTy&>>,
std::invoke_result_t<FunTy, const MGraphTy&>>
{
if constexpr (can_freeze_)
{
if (std::holds_alternative<IGraphTy>(m_graph))
return std::invoke(std::forward<FunTy>(fun), std::get<IGraphTy>(m_graph));
return std::invoke(std::forward<FunTy>(fun), std::get<MGraphTy>(m_graph));
}
else
return std::invoke(std::forward<FunTy>(fun), m_graph);
}
template <typename ColorMapTy>
struct marker_
: boost::default_bfs_visitor
{
constexpr marker_(sample_graph& owner, ColorMapTy& colors)
: m_owner(std::ref(owner)), m_colors(std::ref(colors))
{}
template <typename ArrowTy, typename GraphTy>
void examine_edge(const ArrowTy& a, const GraphTy& g)
{
auto t = boost::target(a, g);
auto&& c = boost::get(m_colors.get(), t);
if (c != boost::white_color || t >= m_owner.get().m_states.size())
return;
if (m_owner.get().m_states[t] >= 4)
{
c = boost::black_color;
return;
}
++m_owner.get().m_states[t];
}
private:
std::reference_wrapper<sample_graph> m_owner;
std::reference_wrapper<ColorMapTy> m_colors;
};
template <typename GraphTy>
static void mark_nodes(sample_graph& o, GraphTy& g, const std::vector<NodeIdTy>& is)
{
auto rg = boost::make_reverse_graph<GraphTy>(g);
auto cs = boost::make_vector_property_map<boost::default_color_type>(boost::get(boost::vertex_index, rg));
auto q = boost::queue<NodeIdTy>();
boost::breadth_first_visit(rg, is.cbegin(), is.cend(), q,
marker_{o, cs}, cs);
// CTAD - implicit deduction causes compiler to crash (adding type argument or explicit guide WA the issue):
//boost::breadth_first_visit(rg, is.cbegin(), is.cend(), q,
// marker_<decltype(cs)>{o, cs}, cs);
}
public:
template <typename CMGraphTy = MGraphTy, typename CIGraphTy = IGraphTy, typename CNodeIdTy = NodeIdTy>
constexpr sample_graph()
{
static_assert(std::integral<CNodeIdTy>);
static_assert(bgl_mutable_graph<CMGraphTy, CNodeIdTy>);
static_assert(bgl_graph<CIGraphTy, CNodeIdTy>);
}
void sample1(const std::vector<NodeIdTy>& is)
{
with_ro_graph([&, this](const auto& g)
{
mark_nodes(*this, g, is);
});
}
private:
my_graph m_graph;
boost::container::deque<int> m_states;
};
template <typename GraphTy>
requires bgl_graph<GraphTy>
void sample_graph1(GraphTy& graph) {
//auto
}
int main()
{
using my_ig = boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS>;
using my_node = my_ig::vertex_descriptor;
sample_graph<my_ig, my_ig, my_node> g;
g.sample1(std::vector<my_node>{});
}
The first sample (that does not compile, but it should) can be reduced a bit:
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc/clang-cl: -std:c++20 -W4 -O2
template <typename T>
struct A
{
template <typename U>
struct B
{
B(A& a, U& b)
: m_a(&a), m_b(&b)
{}
A* m_a;
U* m_b;
};
// Generated implicit deduction is invalid and in more
// complicated scenarios causes compiler to crash.
// The implicit guide is correctly generated on
// msvc and gcc.
//
// If you uncomment this explicit guide it will work:
//template <typename U> B(A&, U&) -> B<U>;
void fun()
{
int a = 1;
B b1{*this, a};
}
};
int main()
{
A<long> a;
a.fun();
}
On latest clang it generates error (args: -std=c++20 -Wall -O2 -pedantic):
<source>:30:11: error: no viable constructor or deduction guide for deduction of template arguments of 'B'
30 | B b1{*this, a};
| ^
<source>:37:7: note: in instantiation of member function 'A<long>::fun' requested here
37 | a.fun();
| ^
<source>:10:9: note: candidate template ignored: deduced conflicting types for parameter 'U' ('long' vs. 'int')
10 | B(A& a, U& b)
| ^
<source>:10:9: note: implicit deduction guide declared as 'template <typename U> B(A<T> &a, U &b) -> B<U>'
<source>:8:12: note: candidate function template not viable: requires 1 argument, but 2 were provided
8 | struct B
| ^
<source>:8:12: note: implicit deduction guide declared as 'template <typename U> B(B<U>) -> B<U>'
1 error generated.
Compiler returned: 1
while compiled without issues on gcc or msvc.
The crash sample can be reduced to the following (I was able to cut out the boost completely):
// clang/gcc: -std=c++20 -Wall -O2 -pedantic
// msvc/clang-cl: -std:c++20 -W4 -O2
#include <concepts>
#include <functional>
#include <type_traits>
#include <variant>
#include <vector>
struct A {};
template <typename MGraphTy,
typename IGraphTy = MGraphTy,
std::integral NodeIdTy = std::size_t>
class sample_graph
{
constexpr static bool can_freeze_ = !std::same_as<std::remove_cvref_t<IGraphTy>, std::remove_cvref_t<MGraphTy>>;
using my_graph = std::conditional_t<can_freeze_, std::variant<MGraphTy, IGraphTy>, MGraphTy>;
template <typename FunTy>
requires std::invocable<FunTy, const MGraphTy&> &&
(!can_freeze_ || std::invocable<FunTy, const IGraphTy&>)
constexpr auto with_ro_graph(FunTy&& fun) const
noexcept(std::is_nothrow_invocable_v<FunTy, const MGraphTy&> &&
(!can_freeze_ || std::is_nothrow_invocable_v<FunTy, const IGraphTy&>))
-> std::conditional_t<can_freeze_,
std::common_type_t<std::invoke_result_t<FunTy, const MGraphTy&>,
std::invoke_result_t<FunTy, const IGraphTy&>>,
std::invoke_result_t<FunTy, const MGraphTy&>>
{
if constexpr (can_freeze_)
{
if (std::holds_alternative<IGraphTy>(m_graph))
return std::invoke(std::forward<FunTy>(fun), std::get<IGraphTy>(m_graph));
return std::invoke(std::forward<FunTy>(fun), std::get<MGraphTy>(m_graph));
}
else
return std::invoke(std::forward<FunTy>(fun), m_graph);
}
template <typename ColorMapTy>
struct marker_
{
constexpr marker_(sample_graph& owner, ColorMapTy& colors)
: m_owner(std::ref(owner)), m_colors(std::ref(colors))
{}
private:
std::reference_wrapper<sample_graph> m_owner;
std::reference_wrapper<ColorMapTy> m_colors;
};
template <typename GraphTy>
static void mark_nodes(sample_graph& o, GraphTy& g, const std::vector<NodeIdTy>& is)
{
static_cast<void>(g);
auto cs = decltype(is){};
static_cast<void>(marker_{o, cs});
// CTAD - implicit deduction causes compiler to crash (to WA the issue
// you can specify type argument):
//static_cast<void>(marker_<decltype(cs)>{o, cs});
}
public:
void sample1(const std::vector<NodeIdTy>& is)
{
with_ro_graph([&, this](const auto& g)
{
mark_nodes(*this, g, is);
});
}
private:
my_graph m_graph;
std::vector<int> m_states;
};
int main()
{
sample_graph<A, A, unsigned> g;
g.sample1(std::vector<unsigned>{});
}
It compiles on msvc and gcc it compiles without issues.
On clang:
- 17.0.1 - build fails with error.
- 18.1.0 and later - crashes compiler.
I was able to get stack trace for latest one:
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -Wall -O2 -pedantic <source>
1. <eof> parser at end of file
2. <source>:69:10: instantiating function definition 'sample_graph<A, A, unsigned int>::sample1'
3. <source>:57:17: instantiating function definition 'sample_graph<A, A, unsigned int>::mark_nodes<const A>'
#0 0x0000000003c51888 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c51888)
#1 0x0000000003c4f26c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3c4f26c)
#2 0x0000000003b91e88 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000079dad4845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x000000000792997f clang::TemplateArgument::getNonTypeTemplateArgumentType() const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x792997f)
#5 0x0000000006cce1f8 checkDeducedTemplateArguments(clang::ASTContext&, clang::DeducedTemplateArgument const&, clang::DeducedTemplateArgument const&, bool) (.part.0) SemaTemplateDeduction.cpp:0:0
#6 0x0000000006ce3bbd DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#7 0x0000000006ce68d3 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, clang::TemplateArgument const&, clang::TemplateArgument, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool*) SemaTemplateDeduction.cpp:0:0
#8 0x0000000006ce7119 DeduceTemplateArguments(clang::Sema&, clang::TemplateParameterList*, llvm::ArrayRef<clang::TemplateArgument>, llvm::ArrayRef<clang::TemplateArgument>, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool, bool, PackFold, bool*) SemaTemplateDeduction.cpp:0:0
#9 0x0000000006ce8861 DeduceTemplateSpecArguments(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, bool, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, bool*) SemaTemplateDeduction.cpp:0:0
#10 0x0000000006ce43f1 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, clang::TemplateParameterList*, clang::QualType, clang::QualType, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, unsigned int, PartialOrderingKind, bool, bool*) SemaTemplateDeduction.cpp:0:0
#11 0x0000000006d0a34f DeduceTemplateArgumentsFromCallArgument(clang::Sema&, clang::TemplateParameterList*, unsigned int, clang::QualType, clang::QualType, clang::Expr::Classification, clang::Expr*, clang::sema::TemplateDeductionInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::Sema::OriginalCallArg>&, bool, unsigned int, unsigned int, clang::TemplateSpecCandidateSet*) SemaTemplateDeduction.cpp:0:0
#12 0x0000000006d0d5dc clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>, bool)>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6d0d5dc)
#13 0x0000000006b6a1c4 AddTemplateOverloadCandidateImmediately(clang::Sema&, clang::OverloadCandidateSet&, clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) SemaOverload.cpp:0:0
#14 0x0000000006b6ab9f clang::OverloadCandidateSet::InjectNonDeducedTemplateCandidates(clang::Sema&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6b6ab9f)
#15 0x0000000006b6abf4 clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6b6abf4)
#16 0x000000000692201c clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>)::'lambda0'(bool)::operator()(bool) const SemaInit.cpp:0:0
#17 0x000000000692294f clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x692294f)
#18 0x0000000006872ab6 clang::Sema::BuildCXXTypeConstructExpr(clang::TypeSourceInfo*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6872ab6)
#19 0x0000000006db0cae clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXUnresolvedConstructExpr(clang::CXXUnresolvedConstructExpr*) SemaTemplateInstantiate.cpp:0:0
#20 0x0000000006d91224 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#21 0x0000000006d9d05e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXStaticCastExpr(clang::CXXStaticCastExpr*) SemaTemplateInstantiate.cpp:0:0
#22 0x0000000006d912b0 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#23 0x0000000006dcc169 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformStmt(clang::Stmt*, clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::StmtDiscardKind) SemaTemplateInstantiate.cpp:0:0
#24 0x0000000006dcc821 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCompoundStmt(clang::CompoundStmt*, bool) SemaTemplateInstantiate.cpp:0:0
#25 0x0000000006dd36f7 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6dd36f7)
#26 0x0000000006e5bb9b clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6e5bb9b)
#27 0x0000000006e5a0e8 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6e5a0e8)
#28 0x0000000006e5bdda clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6e5bdda)
#29 0x0000000006e5a0e8 clang::Sema::PerformPendingInstantiations(bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6e5a0e8)
#30 0x00000000063f2979 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::TUFragmentKind) (.part.0) Sema.cpp:0:0
#31 0x00000000063f2c3d clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x63f2c3d)
#32 0x000000000624910f clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x624910f)
#33 0x0000000006221daa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6221daa)
#34 0x000000000461fde5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x461fde5)
#35 0x0000000004962031 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4962031)
#36 0x00000000048e19f5 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x48e19f5)
#37 0x0000000004a600bb clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a600bb)
#38 0x0000000000dfcdc8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdfcdc8)
#39 0x0000000000df4c9b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#40 0x0000000000df4d3d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#41 0x0000000004694f09 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#42 0x0000000003b92243 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3b92243)
#43 0x0000000004695129 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#44 0x0000000004655552 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4655552)
#45 0x0000000004656431 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4656431)
#46 0x000000000466028c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x466028c)
#47 0x0000000000df976f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdf976f)
#48 0x0000000000d0241a main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd0241a)
#49 0x000079dad482a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#50 0x000079dad482a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#51 0x0000000000df4735 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdf4735)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 139
Reduced:
template <typename, typename, typename>
class sample_graph
{
public:
template <typename ColorMapTy>
struct marker_
{
constexpr marker_(sample_graph&, ColorMapTy) {}
};
};
sample_graph<int, int, unsigned> g;
decltype(g)::marker_ m{g, 0};
See https://compiler-explorer.com/z/6EW46Kc8h.
Assertion:
clang++: /root/llvm-project/llvm/include/llvm/ADT/SmallBitVector.h:457:
llvm::SmallBitVector::reference llvm::SmallBitVector::operator[](unsigned int):
Assertion `Idx < size() && "Out-of-bounds Bit access."' failed.
Stack dump
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++17 <source>
1. <source>:13:29: current parser token ';'
#0 0x000000000434c4d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x434c4d8)
#1 0x0000000004349414 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349414)
#2 0x0000000004349a34 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349a34)
#3 0x0000000004286f78 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007ac792845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007ac79289eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007ac79284527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007ac7928288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007ac79282881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007ac79283b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000076c7225 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x76c7225)
#11 0x00000000076c91f7 MarkUsedTemplateParameters(clang::ASTContext&, clang::QualType, bool, unsigned int, llvm::SmallBitVector&) SemaTemplateDeduction.cpp:0:0
#12 0x00000000076ca53c MarkUsedTemplateParameters(clang::ASTContext&, clang::TemplateArgument const&, bool, unsigned int, llvm::SmallBitVector&) SemaTemplateDeduction.cpp:0:0
#13 0x00000000076c8e09 MarkUsedTemplateParameters(clang::ASTContext&, clang::QualType, bool, unsigned int, llvm::SmallBitVector&) SemaTemplateDeduction.cpp:0:0
#14 0x00000000076c8ce0 MarkUsedTemplateParameters(clang::ASTContext&, clang::QualType, bool, unsigned int, llvm::SmallBitVector&) SemaTemplateDeduction.cpp:0:0
#15 0x0000000007706e28 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>, bool)>)::'lambda0'(clang::QualType, unsigned int, bool)::operator()(clang::QualType, unsigned int, bool) const SemaTemplateDeduction.cpp:0:0
#16 0x0000000007708392 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool, bool, bool, clang::QualType, clang::Expr::Classification, bool, llvm::function_ref<bool (llvm::ArrayRef<clang::QualType>, bool)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7708392)
#17 0x0000000007563f25 AddTemplateOverloadCandidateImmediately(clang::Sema&, clang::OverloadCandidateSet&, clang::FunctionTemplateDecl*, clang::DeclAccessPair, clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>, bool, bool, bool, clang::CallExpr::ADLCallKind, clang::OverloadCandidateParamOrder, bool) SemaOverload.cpp:0:0
#18 0x000000000756486f clang::OverloadCandidateSet::InjectNonDeducedTemplateCandidates(clang::Sema&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x756486f)
#19 0x00000000075648ce clang::OverloadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75648ce)
#20 0x000000000732aa9b clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>)::'lambda0'(bool)::operator()(bool) const SemaInit.cpp:0:0
#21 0x000000000732b8ae clang::Sema::DeduceTemplateSpecializationFromInitializer(clang::TypeSourceInfo*, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x732b8ae)
#22 0x0000000006ff8f4d clang::Sema::deduceVarTypeFromInitializer(clang::VarDecl*, clang::DeclarationName, clang::QualType, clang::TypeSourceInfo*, clang::SourceRange, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ff8f4d)
#23 0x0000000006ffafcd clang::Sema::DeduceVariableDeclarationType(clang::VarDecl*, bool, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ffafcd)
#24 0x000000000702f5c8 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x702f5c8)
#25 0x0000000006c73334 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c73334)
#26 0x0000000006c80c4a clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c80c4a)
#27 0x0000000006c3da0b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c3da0b)
#28 0x0000000006c3e20f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c3e20f)
#29 0x0000000006c45cc1 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c45cc1)
#30 0x0000000006c46bd5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c46bd5)
#31 0x0000000006c27aba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c27aba)
#32 0x0000000004e44b58 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e44b58)
#33 0x000000000517d638 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x517d638)
#34 0x00000000050f936d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50f936d)
#35 0x000000000527c1bd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527c1bd)
#36 0x0000000000dcc82c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcc82c)
#37 0x0000000000dc350a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#38 0x0000000000dc368d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#39 0x0000000004eb7b59 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#40 0x00000000042873b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42873b4)
#41 0x0000000004eb81a6 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#42 0x0000000004e74b42 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e74b42)
#43 0x0000000004e75aee clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e75aee)
#44 0x0000000004e7d325 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e7d325)
#45 0x0000000000dc8da2 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc8da2)
#46 0x0000000000cc8a4a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc8a4a)
#47 0x00007ac79282a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#48 0x00007ac79282a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#49 0x0000000000dc2eb5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc2eb5)
CC @hokein