tree-sitter-cpp icon indicating copy to clipboard operation
tree-sitter-cpp copied to clipboard

C++ attribute fixes

Open Tsche opened this issue 1 year ago • 0 comments

Currently tree-sitter-cpp uses attribute_declaration from the C parser. Since the grammar for attributes is different between C and C++, this is not sufficient.

Namely C++ allows using using in attributes, ie:

[[using gnu: always_inline, visibility("default")]]
inline int g();

//instead of
[[gnu::always_inline]] [[gnu::visibility("default")]]
inline int g();

Consequently tree-sitter-cpp currently errors with the above code. This patch fixes that.



Additionally this patch also implements attributed using-directives such as:

[[deprecated]] using namespace foo;

Currently, using-directives are parsed as using_declaration, consequently it now also accepts invalid using-declarations such as [[deprecated]] using typename foo; and invalid using-enum-declarations such as [[deprecated]] using enum foo;.

Please advise if pulling using-directives into their own using_directive node type is okay - that'd be more correct and alleviate this issue.

Tsche avatar Jul 31 '24 20:07 Tsche