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

Cannot find references for enum class member, but typedef'ed enum member is OK #1197

Closed
fiddleyuan opened this issue Jun 15, 2018 · 5 comments

Comments

@fiddleyuan
Copy link

Not sure if this only happens to me or a common "issue".
Example:
typedef enum
{
Type1,
Type2,
Type3
}Type;
If use rc to find reference for Type1, Type2, Type3, it's working pretty well.

However, for enum class member, like:
enum class Format
{
FormatInvalid = -1,
Format1,
Format2,
Format3,
};
For this situation, rc cannot find reference for above Formats.

Could someone confirm this is only on my side or commonly happens.
Thanks

@casch-at
Copy link
Collaborator

Works for me! Can you provide a step by step instruction how you did it, inclusive the source code. Thanks!

The test file.

#include <iostream>

typedef enum { Type1, Type2, Type3 } Type;

enum class Format {
  FormatInvalid = -1,
  Format1,
  Format2,
  Format3,
};

int main()
{
  Format format = Format::Format3;
  if (format == Format::Format3)
    std::cout << "Format3" << std::endl;
  else if (format == Format::Format2)
    std::cout << "Format2" << std::endl;
  else if (format == Format::Format1)
    std::cout << "Format1" << std::endl;
  else
    std::cout << "Error " << static_cast<std::underlying_type<Format>::type>(Format::FormatInvalid) << std::endl;

  std::cout << "Value of enum class: " << static_cast<std::underlying_type<Format>::type>(Format::Format1) << std::endl;
  std::cout << "Value of enum: " << Type1 << std::endl;;
  return 0;
}

Parse the test file.

rc -c g++ -std=c++11 -Wall -Wextra main.cpp -o main

Christian

@fiddleyuan
Copy link
Author

fiddleyuan commented Jun 16, 2018

Hi Christian,

Regarding step by step instruction, I did submit a issue #1194. To be short, I'm working on a C++/C project which is inside Android. Android build is hard to manipulate, so I use Bear to generate compile_commands.json file, I use Bear's -a option to consolidate several folder's compile commands into one single json file. Then I use rc -J to pass the compile command to rdm. So far, finding symbols and references are pretty good with RTags. Only I suddenly found some enum class variables are not referenced well.

Anyway, I tried your test.cpp file, I used your rc -c line, but I didn't find any outputs from rdm logging.
Then I restart rdm with -v option, it hints me "missing of srcRoot", so I searched issue list, and managed to do "touch README" to trick. It worked, test.cpp was indexed. This is what I got from rdm logging:

Parsed Source(s) successfully: List<Source>(Source(/usr/bin/g++ -Wall -Wextra -ferror-limit=50 -Wall -fspell-checking -Wno-unknown-warning-option -DRTAGS= -isystem /usr/lib/llvm-3.4/lib/clang/3.4/include/ -o /home/shuaiy/proj/temp/test /home/shuaiy/proj/temp/test.cpp Build: /home/shuaiy/proj/temp/ compile_commands: ))
[100%] 1/1 15:18:30 ~/proj/temp/test.cpp in 403ms. (26228 syms, 33406 symNames, 207 includes, 94 of 94 files, symbols: 32683 of 32683, 39946 cursors, 18500164 bytes written, 93 queried 11ms) (83/194/63ms). (priority 0)
Jobs took 0.43s. We're using 4mb of memory.
Query opened 0 files for project /home/shuaiy/proj/temp/
Output from /home/shuaiy/proj/temp/test.cpp:
CI::parse loading unit: clang "-Wall" "-Wextra" "-ferror-limit=50" "-Wall" "-fspell-checking" "-Wno-unknown-warning-option" "-DRTAGS=" "-isystem" "/usr/lib/llvm-3.4/lib/clang/3.4/include/" /home/shuaiy/proj/temp/test.cpp true
Fixit for /home/shuaiy/proj/temp/test.cpp:27:66: Insert ">"
Fixit for /home/shuaiy/proj/temp/test.cpp:29:77: Insert ">"

Then I use rc to find references:

shuaiy@shuaiy-linux:~/proj/temp$ rc -e -R Format3
test.cpp:14:5:      Format3,
shuaiy@shuaiy-linux:~/proj/temp$ rc -e -R Format::Format3
test.cpp:14:5:      Format3,
shuaiy@shuaiy-linux:~/proj/temp$ rc -e -R Type1
test.cpp:30:39:     std::cout << "Value of enum: " << Type1 << std::endl;;
test.cpp:5:5:       Type1,
shuaiy@shuaiy-linux:~/proj/temp$

So I still cannot fine all references for enum class variables, and typedef'ed enum still working OK.
Anything went wrong?

@casch-at
Copy link
Collaborator

I suspect it's because of your Clang/LLVM version you built RTags against. I need to verify this inside a VM. I report back.

"touch README"

--project-root helps you in that case too.

@casch-at
Copy link
Collaborator

I neither couldn't reproduce this in CentOS 7.

rc -w
/home/osboxes/Downloads/ <=
[osboxes@osboxes Downloads]$ rc -e -R Format3
main.cpp:14:27:	  Format format = Format::Format3;
main.cpp:15:25:	  if (format == Format::Format3)
main.cpp:9:3:	  Format3,

Clang/LLVm 3.4.2

Your output of RDM looks differnt though, are you sure, you used the same rc command.

My:

I::parse loading unit: clang "-std=c++11" "-Wall" "-Wextra" "-ferror-limit=50" "-Wall" "-fspell-checking" "-Wno-unknown-warning-option" "-DRTAGS=" "-isystem" "/usr/lib/clang/3.4.2/include/" /home/osboxes/Downloads/main.cpp true

Your:

CI::parse loading unit: clang "-Wall" "-Wextra" "-ferror-limit=50" "-Wall" "-fspell-checking" "-Wno-unknown-warning-option" "-DRTAGS=" "-isystem" "/usr/lib/llvm-3.4/lib/clang/3.4/include/" /home/shuaiy/proj/temp/test.cpp true
Fixit for /home/shuaiy/proj/temp/test.cpp:27:66: Insert ">"
Fixit for /home/shuaiy/proj/temp/test.cpp:29:77: Insert ">"
cd ~/Downloads
rc --project-root . -c g++ -std=c++11 -Wall -Wextra main.cpp -o main

@fiddleyuan
Copy link
Author

Hi Christian,

I just run the rc command again, this time the rdm logging is:

CI::parse loading unit: clang "-std=c++11" "-Wall" "-Wextra" "-ferror-limit=50" "-Wall" "-fspell-checking" "-Wno-unknown-warning-option" "-DRTAGS=" "-isystem" "/usr/lib/llvm-3.4/lib/clang/3.4/include/" /home/shuaiy/proj/temp/test.cpp true

The previous "Fixit" print didn't come out this time, and I'm able to find reference now:

shuaiy@shuaiy-linux:~/proj/temp$ rc -e -R Format3
test.cpp:19:29:     Format format = Format::Format3;
test.cpp:20:27:     if (format == Format::Format3)
test.cpp:14:5:      Format3,
shuaiy@shuaiy-linux:~/proj/temp$

This is peculiar because I didn't modify the test.cpp nor change anything else.
I also tried in new bash session and in previous GNU screen session (where some environment may be override), they all work well. Peculiar, :)

Since the test source code is working well, I will close this issue for now.

But in my Android project, similar enum class variable still cannot find reference for now. I guess I need re-index the project and try to nail down my issue.

Thank you very much, Christian!

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

No branches or pull requests

2 participants