Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 auto keyword support (UE4)
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

bpdburden
Junior Member

12 Posts

Posted - Feb 07 2022 :  12:15:44 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

Thank you for checking. That seems to rule out a macro for T being a problem, but I am not sure what this leaves us with.

Can you please run Find References on T, and in the Find References Results check and see if any results are hidden. This is listed on the bar where the number of results is listed. If any results are hidden you can unhide them with the context menu filters. Also please check and make sure both:

Search all projects (P)
Show Projects

are turned On.

Would you be able to copy the full results and email me the results as a text file? This will contain details of your code, so I don't know if this will be a concern or not, but I am only interested in looking at the results to see if there is anything that offers a clue about what is going wrong here. If I find anything odd or strange I can try to set up versions of it here.

Assuming you can do so, the problem with this approach is that it doesn't include results from your include directories, only your solution, but hopefully it will still help.

If you are able to send me the results, please send me the files via email:

[email protected]

including this thread ID or URL in the description, so we can match it up.



Okay, yes I can send you that. But, fair warning, it's about 10,000 lines.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Feb 08 2022 :  06:37:51 AM  Show Profile  Reply with Quote
I have the file, many thanks for this:

case=147804

It will be treated confidentially, it is just likely to be a little while before I have anything to report. I hope to be able to discard quite a bit of the file fairly quickly, but since I don't know what might be triggering this bug, I need to do so a little carefully.

zen is the art of being at one with the two'ness
Go to Top of Page

Malcolm
New Member

2 Posts

Posted - Dec 08 2022 :  05:38:12 AM  Show Profile  Reply with Quote
Hello! I also apologise for necro'ing this thread, but it seems to mirror my experiences, and I wanted to know if there was any update on the handling of auto, or if there's an issue tracker somewhere that I can have visibility on?

As previous posters have said, VA doesn't always work when I use the auto keyword. I'm working with Unreal 4, so there are lots of UE shenanigans around, but it happens even when I'm steering clear of UObjects. Below is some sample code that I threw into the very top of a random cpp file (in our code, not the engine). The indicated line is where the issue is experienced. No autocomplete list comes up, and, the definition field shows auto Thing so it hasn't been able to work out the type of Thing (although, it has the context correct as func.Thing).
struct Thing1 { void DoStuff1() {} };
struct Thing2 { void DoStuff2() {} };

template<typename T> T GetThing();
template<> Thing1 GetThing<Thing1>() { return Thing1{}; }
template<> Thing2 GetThing<Thing2>() { return Thing2{}; }

void func()
{
	auto Thing{ GetThing<Thing1>() };
	Thing. // <- No autocomplete list here
	GetThing<Thing1>(). // <- this works, autocomplete list shows DoStuff1
}
The template parameter T is slightly interesting; if I put the cursor on it, the Context field just shows T, and the definition field shows constexpr FORCEINLINE const T (&AsConst(T (&Array)[N]))[N] which is a definition within UE's UnrealTemplate.h, and Alt+G takes me to that definition, which is this:
/**
 * Returns a non-const reference type as const.
 * This overload is only required until the pointer overloads are removed.
 */
template <typename T, SIZE_T N>
constexpr FORCEINLINE const T (&AsConst(T (&Array)[N]))[N]
{
	return Array;
}
If I rename T to something definitely unique, it doesn't fix the autocomplete issue, but the Context field and definition field show TemplateParameter.TMyUniqueName234 and typename TMyUniqueName234 respectively. No idea if that's important, but it seemed potentially relevant.

Edit: I just thought to do this, and it was again interesting. I did a VA Find Symbol (Alt+Shift+S) for T and it came up with the above 'AsConst' definition. My unique template parameter name didn't appear in the symbol definitions list.

I look forward to hearing from you, thanks very much!

Edited by - Malcolm on Dec 08 2022 05:47:05 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Dec 12 2022 :  1:21:30 PM  Show Profile  Reply with Quote
Apologies for these problems. I am seeing the same problem with your simple code, but I am not quite sure how to read the line:

auto Thing{ GetThing<Thing1>() };

this is brace initialization, but that is normally used for the components of a struct. But here there is only one component. It almost makes me think of a Tuple with a single item in it. This page on brace initialization seems fairly complete, but it doesn't seem to cover this case:

https://learn.microsoft.com/en-us/cpp/cpp/initializing-classes-and-structs-without-constructors-cpp?view=msvc-170

and to be honest I never thought of doing this with brace initialization.

VA doesn't understand what you are doing here, so it isn't working out the correct type for the auto variable, which I have confirmed without even using any templates. So UE and templates is actually a red herring in this particular situation. Do you often do this?

OK, testing this, with the simplified code sample:

struct StructToCreate { void DoStuff1() {} };
	
void func()
{
	StructToCreate localFoo1;
	// this code compiles in VS2013 and above, does not compile in VS2012
	auto CreateStructInstance{ localFoo1 };
	// BUG - VA shows no listbox when typing dot after "CreateStructInstance"
	// BUG - Goto Related cannot show members of this type
	CreateStructInstance;
	// this does NOT compile in VS2013, since in VS2013 auto type is std::initializer_list<StructToCreate>
	// this Does compile in VS2015 and above
	CreateStructInstance.DoStuff1();
}

it only compiles in recent enough versions of Visual Studio. That's what I get for trying to be thorough

We are working to make sure VA's support for brace initialization is solid, so I think this belongs as part of that case:

case=141519

zen is the art of being at one with the two'ness
Go to Top of Page

Malcolm
New Member

2 Posts

Posted - Dec 12 2022 :  4:17:01 PM  Show Profile  Reply with Quote
That line is indeed braced initialization of a sort. It's specifically list initialization (https://en.cppreference.com/w/cpp/language/list_initialization). The relevant part of the explanation states:
quote:
The effects of list-initialization of an object of type T are:
If T is an aggregate class and the braced-init-list has a single element of the same or derived type (possibly cv-qualified), the object is initialized from that element (by copy-initialization for copy-list-initialization, or by direct-initialization for direct-list-initialization).


As of C++11 you can initialize variables in this way, and it provides a more consistent initialization syntax, although you do have to be careful about initializer_lists. I found this article to be a good summary of the situation, https://blog.quasar.ai/2017/03/05/cpp-braced-initialization, and it mentions Item 7 in Scott Meyers' book "Effective Modern C++", which is worth reading if you have access to it. We do often use this syntax, for the reasons given in the book (summarised in the article), and I expect it has quite a widespread usage, given the notability of Scott Meyers' writing.

Thank you for referencing the case number (141519), is there somewhere I can look to see how that case is progressing?

FYI: As a test, I tried using direct initialization (auto Thing( GetThing<Thing1> );) and copy initialization (auto Thing = GetThing<Thing1>();) and Visual Assist evaluated everything correctly.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Dec 13 2022 :  07:17:50 AM  Show Profile  Reply with Quote
It has been a while since I last read Scott Meyers, but I recall being really impressed by his books Thank you for explaining what is going on here. Once I knew it was compiling I could see what was happening, and in a way it is clearer than the round backet constructor call, but it was unexpected the first time I saw it.

Unfortunately our bug tracker isn't publicly visible, but this thread will be updated when this has been fixed, and you can always ask for updates. As more people run into a problem or limitation of our parser then it becomes more urgent to address it, so knowing how many people are encountering this will be useful.

zen is the art of being at one with the two'ness

Edited by - feline on Dec 13 2022 07:20:15 AM
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000