Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CPyCppyy/src/CPyCppyyModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static PyObject* MakeCppTemplateClass(PyObject* /* self */, PyObject* args)
if (!scope) {
PyErr_Format(PyExc_TypeError,
"Template instantiation failed: '%s' with args: '%s\n'",
Cppyy::GetScopedFinalName(cppscope).c_str(),
Cppyy::GetScopedFinalName(tmpl).c_str(),
CPyCppyy_PyText_AsString(PyObject_Repr(args)));
return nullptr;
}
Expand Down
5 changes: 4 additions & 1 deletion src/backend/clingwrapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,10 @@ bool Cppyy::AppendTypesSlow(const std::string& name,

for (const std::string& candidate : candidates) {
std::string var = "__Cppyy_s" + std::to_string(struct_count++);
if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + candidate + "> " + var + ";\n").c_str(), /*silent=*/true)) {
// nodebug: with -g the variable's debug info would carry the full DIE
// tree of every template argument (all member declarations included) --
// a large, uncacheable per-lookup cost on heavyweight types.
if (!Cpp::Declare(("__Cppyy_AppendTypesSlow<" + candidate + "> __attribute__((nodebug)) " + var + ";\n").c_str(), /*silent=*/true)) {
TCppType_t varN =
Cpp::GetVariableType(Cpp::GetNamed(var.c_str(), /*parent=*/nullptr));
TCppScope_t instance_class = Cpp::GetScopeFromType(varN);
Expand Down
15 changes: 15 additions & 0 deletions test/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,21 @@ def test39_monkey_patching_template_proxy(self):
assert a.m([1, 2, 3])
assert not a.m(42)

def test40_instantiation_failure_error_message(self):
"""Rejected instantiation names the template, not garbage"""

import cppyy

cppyy.cppdef("namespace errpath { template <unsigned N> struct Buf { int tag; }; }")

# Check that the failed instantiation error message contains the
# correct template name.
with raises(TypeError) as exc:
cppyy.gbl.errpath.Buf["int"]
msg = str(exc.value)
assert "errpath::Buf" in msg
assert "<unnamed>" not in msg


@mark.skipif((IS_MAC and IS_CLING), reason="setup class fails with OS X cling")
class TestTEMPLATED_TYPEDEFS:
Expand Down
Loading