From 7dafde46dc82bbb23308c3681982e1b944ba8d86 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Sat, 30 May 2026 23:21:07 +0200 Subject: [PATCH] test(c-lsp): regression for issue #312 (defaulted template param + auto) A C++ function template with a defaulted type param and an `auto` parameter, called with matching arg count, previously segfaulted in the definitions pass (unbound `U` flowed through type substitution as NULL). Fixed by the cbm_type_substitute NULL-preservation guard; this locks in a reproduction so it can't regress. Closes #312. --- tests/test_c_lsp.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_c_lsp.c b/tests/test_c_lsp.c index 695297e1c..f1fc4df3e 100644 --- a/tests/test_c_lsp.c +++ b/tests/test_c_lsp.c @@ -581,6 +581,24 @@ TEST(clsp_nocrash_template_function_multi_param_nested_call) { PASS(); } +/* Issue #312: indexing segfaulted in pass=definitions on a function template + * with a defaulted type param AND an `auto` parameter, called with matching + * arg count. The defaulted/unbound template param `U` flowed through type + * substitution as NULL and was dereferenced during return-type handling. */ +TEST(clsp_nocrash_issue312_default_template_auto_param) { + CBMFileResult *r = extract_cpp("template\n" + "U f(auto, T t) {\n" + " return t;\n" + "}\n" + "\n" + "int main() {\n" + " if (f(1, 2) != 2) return 1;\n" + "}\n"); + ASSERT_NOT_NULL(r); + cbm_free_result(r); + PASS(); +} + TEST(clsp_nocrash_lambda) { CBMFileResult *r = extract_cpp("\n" "void test() {\n" @@ -15144,6 +15162,7 @@ SUITE(c_lsp) { RUN_TEST(clsp_nocrash_template_expression); RUN_TEST(clsp_nocrash_template_extra_call_args); RUN_TEST(clsp_nocrash_template_function_multi_param_nested_call); + RUN_TEST(clsp_nocrash_issue312_default_template_auto_param); RUN_TEST(clsp_nocrash_lambda); RUN_TEST(clsp_nocrash_nested_namespace); RUN_TEST(clsp_nocrash_empty_source);