From 4b73c44133534226d2e2599c4a47fe8fb5b08903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 19 Mar 2018 21:33:34 +0100 Subject: [PATCH] Fix issue with array function arguments Fixes #47. --- src/libclang/cxtokenizer.cpp | 6 ++++-- test/cpp_member_function.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libclang/cxtokenizer.cpp b/src/libclang/cxtokenizer.cpp index b502fdb..d374cef 100644 --- a/src/libclang/cxtokenizer.cpp +++ b/src/libclang/cxtokenizer.cpp @@ -276,8 +276,10 @@ namespace auto parent = clang_getCursorLexicalParent(cur); end = clang_getRangeEnd(clang_getCursorExtent(parent)); } - else if (kind == CXCursor_FieldDecl || kind == CXCursor_ParmDecl - || kind == CXCursor_NonTypeTemplateParameter + else if (kind == CXCursor_ParmDecl && !token_after_is(tu, file, end, "]", -1)) + // need to shrink range by one + end = get_next_location(tu, file, end, -1); + else if (kind == CXCursor_FieldDecl || kind == CXCursor_NonTypeTemplateParameter || kind == CXCursor_TemplateTemplateParameter #if CINDEX_VERSION_MINOR < 37 || clang_isExpression(kind) || kind == CXCursor_CXXBaseSpecifier diff --git a/test/cpp_member_function.cpp b/test/cpp_member_function.cpp index 4aecede..84b25d5 100644 --- a/test/cpp_member_function.cpp +++ b/test/cpp_member_function.cpp @@ -16,8 +16,8 @@ TEST_CASE("cpp_member_function") template struct foo { - /// void a(); - void a(); + /// void a(int array[]); + void a(int array[]); // throw in an array argument for good measure /// void b()noexcept; void b() noexcept; @@ -41,9 +41,9 @@ struct foo void j() = delete; }; -/// void foo::a(); +/// void foo::a(int array[]); template -void foo::a() {} +void foo::a(int array[]) {} struct bar : foo { @@ -74,7 +74,7 @@ struct bar : foo REQUIRE(func.is_definition()); REQUIRE(func.cv_qualifier() == cpp_cv_none); REQUIRE(func.ref_qualifier() == cpp_ref_none); - REQUIRE(func.signature() == "()"); + REQUIRE(func.signature() == "(int[])"); } else if (func.name() == "b") {