tree-sitter / tree-sitter/tree-sitter-cpp
bug: parse error on `extern "C" using foobar = void (*)(void);`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 453
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-cpp
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)
0.25.1
Describe the bug
tree-sitter-cpp does not understand an extremely obscure using declaration: extern "C" on function pointer type alias declarations, for strict correctness in not mixing linkage; though I think most compilers do not care because programmers are way too sloppy to get away with enforcing it.
extern "C" using NixPluginEntry = void (*)();
Compiles successfully with clang++ -std=c++23 -c test.cpp.
Steps To Reproduce/Bad Parse Tree
Apply this patch to your tree-sitter-cpp:
diff --git a/test/corpus/declarations.txt b/test/corpus/declarations.txt
index acaf288..d0dec09 100644
--- a/test/corpus/declarations.txt
+++ b/test/corpus/declarations.txt
@@ -106,6 +106,8 @@ using a = typename b<T>::c;
using foobar [[deprecated]] = int;
using foobar [[deprecated]] [[maybe_unused]] = int;
+extern "C" using foobar = void (*)(void);
+
--------------------------------------------------------------------------------
(translation_unit
Run tree-sitter test.
Obtain parse failure:
(linkage_specification
(string_literal
(string_content))
(declaration
(type_identifier)
(init_declarator
(identifier)
(call_expression
(call_expression
(primitive_type)
(argument_list
(ERROR)))
(argument_list
(ERROR
(primitive_type))))))))
Expected Behavior/Parse Tree
I don't know what the parse tree should look like, I just know the highlight broke and there should not be ERROR nodes in there.
Repro
extern "C" using foobar = void (*)(void);
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with test/corpus/declarations.txt, add the supplied reproduction, and run tree-sitter test to inspect the failing parse. Trace how the C++ grammar handles extern "C" and using declarations; done means this case parses without ERROR nodes and the regression test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100