Author |
Topic |
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Jul 31 2024 : 02:18:38 AM
|
I'm using Visual Studio 2022 17.10.5 and VA 2528 I create a new project for Android so library and copy the test code below: class CFelineUniqueShapeSquare { public: // testing Find References on these two member functions - always finds 2 results void RenderFillShape() {} std::string GetSquareName() { return "Yellow Square"; } };
class CFelineUniqueShapeCircle { public: // testing Find References on these two member functions - always finds 2 results void RenderFillShape() {} std::string GetCircleName() { return "Blue Circle"; } };
void FelineStdUniquePtr() { std::unique_ptr<CFelineUniqueShapeSquare> uniqueSquarePtr; std::unique_ptr<CFelineUniqueShapeCircle> uniqueCirclePtr;
// testing Find References on these two function calls - always finds 2 results uniqueSquarePtr->RenderFillShape(); uniqueSquarePtr->GetSquareName();
// testing Find References on these two function calls - always finds 2 results uniqueCirclePtr->RenderFillShape(); uniqueCirclePtr->GetCircleName(); } These code are from https://forums.wholetomato.com/forum/topic.asp?TOPIC_ID=20472
Then I Find References for RenderFillShape, only one result shows.
Both shared_ptr and unique_ptr have this problem, but it works fines with normal pointer.
I'm also using VS for Windows, Find References still works fine.
|
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Jul 31 2024 : 02:27:09 AM
|
I've tried Visual Studio 2022 17.10.4 and VA 2522, but the issue remains the same. |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Jul 31 2024 : 09:24:05 AM
|
Can you please try creating a new, default C++ solution and see if you get the same problem there?
If you do see the same problem there, could you please send me the test solution?
So far I cannot reproduce the problem here. I am wondering if the version of the C++ libraries you are using is a factor. If you use Alt-Shift-G, for Goto Related, on "std::unique_ptr" and open the "Goto Member..." box, how many members are listed for you for this type? 16 members are being listed for me, including "operator->" |
zen is the art of being at one with the two'ness |
|
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Jul 31 2024 : 11:16:26 PM
|
If by 'default C++ solution' you mean a console application for Windows, the "Find References" works fine. This only happens when I create a Android shared library solution. You may be right about the version of the C++ libraries. There are 16 members for unique_ptr on console application for Windows, but there are 26 on Android shared library solution. |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Aug 02 2024 : 10:35:39 AM
|
Apologies, I realised you did say that in your original post, but I missed it.
I have reproduced the problem now, and am trying to figure out what is causing it. Hopefully once I understand the trigger, I can suggest a work around. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Aug 16 2024 : 11:50:02 AM
|
Apologies for the slow reply, I went down various dead ends trying to understand why this wasn't working. I believe I have a solution now though. Can you please make a new, empty text file called "va_stdafx.h" in the same directory as your SLN file, for this project.
Edit the file and give it the following content, making sure that it ends with a blank line:
namespace std
{
template <class _Tp>
class unique_ptr
{
public:
_Tp operator->() const;
};
}; Can you then press the button:
VA Options -> Performance -> Rebuild symbol databases
and restart Visual Studio.
VA searches for this file when first parsing a solution, and if found, it parses it before parsing anything else. The file is used to give our parser a helping hand when it runs into code that otherwise confuses it.
In this case, the return type of "operator->()" in the Android SDK isn't the template type, but VA isn't correctly following the jump from the template type to the functions return type.
Using this file is fixing the problem for me in my tests here.
I have put in a bug report for this as well:
case=164876 |
zen is the art of being at one with the two'ness |
|
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Aug 18 2024 : 11:46:48 PM
|
First of all, I sincerely appreciate your hard work and effort. I've tried your work around. For most situations, it works very well. There's another issue related to "unique_ptr/shared_ptr" and "Find References", but it's not related to Android sln. It can also be reproduced on the Windows platform sln. Since my original project is very complex, I tried to narrow the cause and found that it might be related to template Singleton class. Below is a sample code that can reproduce this issue.
template <typename T> class TSingleton { public: static T& GetInstance() { static T Instance; return Instance; }
TSingleton(const TSingleton&) = delete; TSingleton& operator=(const TSingleton&) = delete;
virtual ~TSingleton() = default;
protected: TSingleton() {} };
class CFelineUniqueShapeSquare { public: void RenderFillShape() {} std::string GetSquareName() { return "Yellow Square"; } };
class CFelineUniqueShapeCircle { public: void RenderFillShape() {} std::string GetCircleName() { return "Blue Circle"; } };
class SingletonClass : public TSingleton<SingletonClass> { class InternalClass;
std::unique_ptr<CFelineUniqueShapeSquare> uniqueSquarePtr; std::unique_ptr<CFelineUniqueShapeCircle> uniqueCirclePtr; };
class SingletonClass::InternalClass { void FelineStdUniquePtr() { GetInstance().uniqueSquarePtr->RenderFillShape(); GetInstance().uniqueSquarePtr->GetSquareName();
GetInstance().uniqueCirclePtr->RenderFillShape(); GetInstance().uniqueCirclePtr->GetCircleName(); } };
If you do "Find References" on "uniqueSquarePtr" in the function "FelineStdUniquePtr", it works perfert. But if you then use "Find References" on "RenderFillShape", the results don't change at all.
Finally, I would like to thank you once again for your help. |
|
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Aug 18 2024 : 11:49:14 PM
|
I tried using regular pointers again and found that the issue still persists, so the problem should be unrelated to unique_ptr or shared_ptr. I hope this information can be of some help to you. |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Aug 19 2024 : 09:18:20 AM
|
Thank you for the sample code, I am seeing the same problem here. Is this how you normally do a singleton class? It's a more complex method that I expected.
I am trying to figure out where and why VA is getting confused, with the aim of finding a work around. |
zen is the art of being at one with the two'ness |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Aug 19 2024 : 10:31:57 AM
|
Is changing how you have constructed your singleton class an option? I am having troubles getting our parser to make sense of this code. I have put in a bug report for this, but for now, the best solution I can suggest would be to try using a simpler way of setting up a singleton class:
case=164877 |
zen is the art of being at one with the two'ness |
|
|
pqy
New Member
United Kingdom
6 Posts |
Posted - Aug 20 2024 : 03:25:21 AM
|
By changing the template class to a macro definition, this issue was indeed resolved. But I've already find a work around. Use 'Goto Implementation' once before the second 'Find References', then the result will be correct.
Below is the macro definition for the singleton class, if anyone needs it.
#define DECLARE_SINGLETON(ClassName) public: static ClassName& GetInstance() { static ClassName instance; return instance; } ClassName(const ClassName&) = delete; ClassName& operator=(const ClassName&) = delete; private: ClassName() {} |
|
|
feline
Whole Tomato Software
United Kingdom
19020 Posts |
Posted - Aug 21 2024 : 07:57:29 AM
|
Thank you for the update, and I am glad you have found a work around here that works well for you.
Are you having any more problems with the Android SDK classes? Given there was one problem, I would not be surprised to find further problems, but without trying to test all of the normal STD classes myself, it is hard to know where to look. |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|