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
 Code Inspection bug
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jschroedl
Tomato Guru

USA
103 Posts

Posted - Jun 28 2017 :  11:25:44 AM  Show Profile  Reply with Quote
The dtor of this class is flagged as one which could be replaced with '= default' in the Code Inspection window but that's incorrect. (VA Build 10.9.2223.0 built 2017.06.22)


// Class to log peformance times
class LogTimer
{
public:
	LogTimer(JString msg=JString::empty())
	{ 
		mStart = std::chrono::high_resolution_clock::now();
		mMsg = msg;
	}
	~LogTimer()
	{
		*logStream() << NEWLINE << mMsg << std::chrono::duration<double, std::milli>(std::chrono::high_resolution_clock::now() - mStart).count();
	}
private:
	std::chrono::steady_clock::time_point mStart;
	JString mMsg;
};




John

Edited by - jschroedl on Jun 28 2017 11:27:32 AM

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Jun 28 2017 :  3:52:15 PM  Show Profile  Reply with Quote
I am seeing the same effect here. Thank you for the clear description.

case=109256

On your system, is Code Inspector offering to do a quick fix for the destructor? I get the same suggestion here, but no quick fix is offered, so I am just wondering if you are seeing the same thing.

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

jschroedl
Tomato Guru

USA
103 Posts

Posted - Jun 29 2017 :  09:55:17 AM  Show Profile  Reply with Quote
quote:
Originally posted by feline

I am seeing the same effect here. Thank you for the clear description.

case=109256

On your system, is Code Inspector offering to do a quick fix for the destructor? I get the same suggestion here, but no quick fix is offered, so I am just wondering if you are seeing the same thing.



No, it does not offer a quick fix for me either.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Jun 29 2017 :  10:29:13 AM  Show Profile  Reply with Quote
Thank you for the update, at least this way the quick fix cannot be accidentally triggered. That would have converted this from concerning to quite worrying.

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

jschroedl
Tomato Guru

USA
103 Posts

Posted - Jul 14 2017 :  11:26:55 AM  Show Profile  Reply with Quote
I ran into another case of this today but it also adds a QF suggestion on the ctor (solid underline) which when applied will be invalid code.

class CCoInitialize {
	HRESULT m_hr;

public:
	CCoInitialize() : m_hr(CoInitialize(nullptr)) {};
	~CCoInitialize() { if (SUCCEEDED(m_hr)) CoUninitialize(); }
	operator HRESULT() const { return m_hr; }
};


If I use the Quick Fix for the ctor (dtor has same bad suggestion as this thread showed before), the ctor is now not legal:

	CCoInitialize() : m_hr(CoInitialize(nullptr)) = default;;

Edited by - jschroedl on Jul 14 2017 11:28:02 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Jul 14 2017 :  1:33:52 PM  Show Profile  Reply with Quote
I am seeing the same result, but a very simple test class doing the same thing on the constructor is handled correctly by Code Inspection, I am not offered the option to replace the constructor body with = default.

So there is something different about this example. But what really confuses me is that this example, before Code Inspection changes it, does not compile in VS2015. I am getting the error:

error C3861: 'CoInitialize': identifier not found

on the constructor. There is an operator to convert the class to a HRESULT, so I am not sure why this is failing to compile, but it is failing. When I change the constructor m_hr initialisation into something that does compile for me, Code Inspection no longer suggests it can be replaced with = default.

Just to make sure I am not missing something new I have tried VS2017, and again the code fails to compile, with the same error.

Does this sample compile for you?

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

jschroedl
Tomato Guru

USA
103 Posts

Posted - Jul 14 2017 :  5:11:03 PM  Show Profile  Reply with Quote
This compiles in VS 2017, you are probably missing the usual Windows headers. For us, these are included as part of the PCH in stdafx.cpp.

CoInitialize:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543 v=vs.85 .aspx
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18750 Posts

Posted - Jul 15 2017 :  07:52:53 AM  Show Profile  Reply with Quote
That was it, this compiles just fine in VS2015 in a Win32 project. My main test solution is a bit of a mess, for testing different things, but it does compile, just

case=109725

Thank you for the very simple and clear example, and the pointer on how to get this to compile.

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

sean
Whole Tomato Software

USA
2817 Posts

Posted - Sep 26 2017 :  10:59:07 PM  Show Profile  Reply with Quote
case=109725 is fixed in build 2235
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000