KDAB / codebrowser

Woboq CodeBrowser
http://woboq.com/codebrowser.html
Other
1.1k stars 161 forks source link

Issues about defining in private and calling in destructor (in llvm/clang-16 and later) #117

Closed ryftchen closed 12 months ago

ryftchen commented 1 year ago

Firstly, thanks for the help in fixing the anonymous struct/union problem (https://github.com/KDAB/codebrowser/issues/116). However, after compiling with the latest commit, the following problem remains. It also worked fine before llvm/clang-16:

[3%] Processing /root/foo/algorithm/source/match.cpp
[6%] Processing /root/foo/algorithm/source/notation.cpp
Error: /root/foo/algorithm/source/notation.cpp:85: 'Priority' is a private member of 'algorithm::notation::Notation'
[10%] Processing /root/foo/algorithm/source/optimal.cpp
Error: /root/foo/algorithm/source/optimal.cpp:251: 'Population' is a private member of 'algorithm::optimal::Genetic'
Error: /root/foo/algorithm/source/optimal.cpp:440: 'Chromosome' is a private member of 'algorithm::optimal::Genetic'
[13%] Processing /root/foo/application/core/source/command.cpp
Error: /root/foo/application/core/source/command.cpp:228: call to non-static member function without an object argument
[17%] Processing /root/foo/application/core/source/config.cpp
[20%] Processing /root/foo/application/core/source/log.cpp
[24%] Processing /root/foo/application/core/source/main.cpp
[27%] Processing /root/foo/application/core/source/view.cpp
[31%] Processing /root/foo/application/example/source/apply_algorithm.cpp
[34%] Processing /root/foo/application/example/source/apply_data_structure.cpp
[37%] Processing /root/foo/application/example/source/apply_design_pattern.cpp
[41%] Processing /root/foo/application/example/source/apply_numeric.cpp
[44%] Processing /root/foo/data_structure/source/linear.cpp
[48%] Processing /root/foo/data_structure/source/tree.cpp
[51%] Processing /root/foo/design_pattern/source/behavioral.cpp
Error: /root/foo/design_pattern/source/behavioral.cpp:80: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:138: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:168: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:224: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:317: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:427: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/behavioral.cpp:468: call to non-static member function without an object argument
[55%] Processing /root/foo/design_pattern/source/creational.cpp
Error: /root/foo/design_pattern/source/creational.cpp:121: call to non-static member function without an object argument
[58%] Processing /root/foo/design_pattern/source/structural.cpp
Error: /root/foo/design_pattern/source/structural.cpp:19: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/structural.cpp:81: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/structural.cpp:220: call to non-static member function without an object argument
Error: /root/foo/design_pattern/source/structural.cpp:261: call to non-static member function without an object argument
[62%] Processing /root/foo/numeric/source/arithmetic.cpp
[65%] Processing /root/foo/numeric/source/divisor.cpp
[68%] Processing /root/foo/numeric/source/integral.cpp
[72%] Processing /root/foo/numeric/source/prime.cpp
[75%] Processing /root/foo/utility/source/argument.cpp
[79%] Processing /root/foo/utility/source/common.cpp
[82%] Processing /root/foo/utility/source/console.cpp
Error: /root/foo/utility/source/console.cpp:67: call to non-static member function without an object argument
[86%] Processing /root/foo/utility/source/file.cpp
Error: /root/foo/utility/source/file.cpp:75: call to non-static member function without an object argument
[89%] Processing /root/foo/utility/source/json.cpp
Error: /root/foo/utility/source/json.cpp:375: call to non-static member function without an object argument
[93%] Processing /root/foo/utility/source/socket.cpp
Error: /root/foo/utility/source/socket.cpp:28: call to non-static member function without an object argument
Error: /root/foo/utility/source/socket.cpp:28: '~Socket' is a protected member of 'utility::socket::Socket'
[96%] Processing /root/foo/utility/source/thread.cpp
Error: /root/foo/utility/source/thread.cpp:54: call to non-static member function without an object argument
[100%] Processing /root/foo/utility/source/time.cpp

1. if the enum or type alias is defined in private and used as the return type for other member functions, the following prompt appears:

Error: /root/foo/algorithm/source/notation.cpp:85: 'Priority' is a private member of 'algorithm::notation::Notation'
Error: /root/foo/algorithm/source/optimal.cpp:440: 'Chromosome' is a private member of 'algorithm::optimal::Genetic'
Waqar144 commented 1 year ago
  1. it seems that a call to the member function in a destructor causes the following (or the destructor is defined as a protected member):

This is fixed with (clang 17): https://github.com/llvm/llvm-project/commit/5a9abe846617efea4a128134db0915a044d7dd73

Can you comment the following line: https://github.com/KDAB/codebrowser/blob/f17b52321d7fb31d2289da9ff209656bcb33bf37/generator/main.cpp#L168 and see if it a) fixes the issue and b) impacts the output?

I am not sure if we need incremental extensions, not sure why it is there at all in the first place. The behaviour has changed so perhaps its time to remove it.

As for your other issue, I was not able to reproduce it.

ryftchen commented 1 year ago
  1. it seems that a call to the member function in a destructor causes the following (or the destructor is defined as a protected member):

This is fixed with (clang 17): llvm/llvm-project@5a9abe8

Can you comment the following line:

https://github.com/KDAB/codebrowser/blob/f17b52321d7fb31d2289da9ff209656bcb33bf37/generator/main.cpp#L168

and see if it a) fixes the issue and b) impacts the output? I am not sure if we need incremental extensions, not sure why it is there at all in the first place. The behaviour has changed so perhaps its time to remove it.

As for your other issue, I was not able to reproduce it.

@Waqar144 Thanks for your support.

BTW, it seems to generate new compile warnings in version 17, maybe we can fix this together with issue 1.

[ 76%] Building CXX object generator/CMakeFiles/codebrowser_generator.dir/inlayhintannotator.cpp.o
/workspaces/codebrowser/generator/inlayhintannotator.cpp:273:52: warning: 'startswith_insensitive' is deprecated: Use starts_with_insensitive instead [-Wdeprecated-declarations]
  273 |     if (f->getNumParams() == 1 && getSimpleName(f).startswith_insensitive("set"))
      |                                                    ^~~~~~~~~~~~~~~~~~~~~~
      |                                                    starts_with_insensitive
/usr/lib/llvm-17/include/llvm/ADT/StringRef.h:267:19: note: 'startswith_insensitive' has been explicitly marked deprecated here
  267 |     [[nodiscard]] LLVM_DEPRECATED(
      |                   ^
/usr/lib/llvm-17/include/llvm/Support/Compiler.h:155:50: note: expanded from macro 'LLVM_DEPRECATED'
  155 | #define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
      |                                                  ^
1 warning generated.
[ 84%] Linking CXX executable codebrowser_generator
Waqar144 commented 1 year ago

Will this code be removed finally, or is it involved in some other function?

I think its best to disable it for now as the meaning of the function has changed and we don't know what other side effects this can introduce.

BTW, it seems to generate new compile warnings in version 17, maybe we can fix this together with issue 1.

Yes, they need to be fixed soon.

Waqar144 commented 12 months ago

Fixed in master.

Warnings not fixed yet.