Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: fully qualified return type breaks parsing prototypes #3693

Closed
b4n opened this issue Apr 6, 2023 · 3 comments · Fixed by #3694
Closed

C++: fully qualified return type breaks parsing prototypes #3693

b4n opened this issue Apr 6, 2023 · 3 comments · Fixed by #3694
Assignees

Comments

@b4n
Copy link
Member

b4n commented Apr 6, 2023

The name of the parser:

C++

The command line you used to run ctags:

$ ctags --options=NONE --C++-kinds=+p -o- foo.cxx

The content of input file:

#include <string>

::std::string bar();
::std::string baz() { return "not a prototype"; }

The tags output you are not satisfied with:

baz	foo.cxx	/^::std::string baz() { return "not a prototype"; }$/;"	f	typeref:typename:::std::string

The tags output you expect:

bar	foo.cxx	/^::std::string bar();$/;"	p	typeref:typename:::std::string	file:
baz	foo.cxx	/^::std::string baz() { return "not a prototype"; }$/;"	f	typeref:typename:::std::string

The version of ctags:

$ ./ctags --version
Universal Ctags 6.0.0(c260d9e8), Copyright (C) 2015-2022 Universal Ctags Team
Universal Ctags is derived from Exuberant Ctags.
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Apr  6 2023, 15:34:13
  URL: https://ctags.io/
  Output version: 0.0
  Optional compiled features: +wildcards, +regex, +iconv, +option-directory, +xpath, +yaml, +packcc, +optscript, +pcre2

How do you get ctags binary:

Built it locally under Debian GNU/Linux Testing.

Details:

If you remove the leading :: from the return type (e.g. remove the FQ property) for the prototype that is missing here, it is properly recognized:

#include <string>

std::string bar();
::std::string baz() { return "not a prototype"; }
$ ctags --options=NONE --C++-kinds=+p -o- foo.cxx
bar	foo.cxx	/^std::string bar();$/;"	p	typeref:typename:std::string	file:
baz	foo.cxx	/^::std::string baz() { return "not a prototype"; }$/;"	f	typeref:typename:::std::string

This seems to happen in any context (e.g. it's the same inside a class or such, and same with a pure virtual method using a FQ return type).

@masatake masatake self-assigned this Apr 6, 2023
@masatake
Copy link
Member

masatake commented Apr 7, 2023

About the reported case, the following change fixes the issue.
I'll take more time for this.

diff --git a/parsers/cxx/cxx_parser.c b/parsers/cxx/cxx_parser.c
index 63256ba8a..6ed9a83dd 100644
--- a/parsers/cxx/cxx_parser.c
+++ b/parsers/cxx/cxx_parser.c
@@ -1497,7 +1497,8 @@ void cxxParserAnalyzeOtherStatement(void)
 
        CXXToken * t = cxxTokenChainFirst(g_cxx.pTokenChain);
 
-       if(!cxxTokenTypeIsOneOf(t,CXXTokenTypeIdentifier | CXXTokenTypeKeyword))
+       if(!cxxTokenTypeIsOneOf(t,CXXTokenTypeIdentifier | CXXTokenTypeKeyword
+                                                       | CXXTokenTypeMultipleColons))
        {
                CXX_DEBUG_LEAVE_TEXT("Statement does not start with an identifier or keyword");
                return;

@b4n
Copy link
Member Author

b4n commented Apr 7, 2023

@masatake you rock, thanks! I'll test this in the coming days. It's really annoying me lately as I'm working a lot on code full of these kind of pure virtual prototypes, and it breaks autocompletion.

masatake added a commit to masatake/ctags that referenced this issue Apr 7, 2023
Close universal-ctags#3693.

The original code could not extract "bar" in

  ::std::string bar();

Signed-off-by: Masatake YAMATO <[email protected]>
@masatake
Copy link
Member

masatake commented Apr 7, 2023

@b4n, thank you for testing. I opened the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants