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 "ctor not initialize all fields"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

azur
Senior Member

Germany
46 Posts

Posted - Sep 27 2022 :  04:01:27 AM  Show Profile  Reply with Quote
The code issue & checker Find manually-defined constructor definitions that do not initialize all fields could be more helpful if the fields leading to this match are displayed.
If the word "field" were then pronounced as a link in the tooltip, the fields could then be displayed in a dialog.
Maybe I just don't know a hotkey to display this information right now.

feline
Whole Tomato Software

United Kingdom
17972 Posts

Posted - Sep 27 2022 :  07:33:50 AM  Show Profile  Reply with Quote
The code inspection is designed to do the initialization for you, automatically. Consider the following example:

class TestCodeInspectConstructorInitSimpleFields
{
	char m_cCharData;
	short m_nShortData;
	int m_nIntData;
	long m_nLongData;
	float m_fFloatData;
	double m_fDoubleData;
	
	// underlined, initializes all members above #CodeInspectConstructorInitAll
	TestCodeInspectConstructorInitSimpleFields() { }
	// underlined, initializes three members above #CodeInspectConstructorInitAll
	TestCodeInspectConstructorInitSimpleFields(bool bInitSome) : m_cCharData('0'), m_nShortData(0), m_fFloatData(0.1f) {}
	// not underlined here, since all fields are initalized
	TestCodeInspectConstructorInitSimpleFields(std::string strInitAll)
	{
		m_cCharData = '0';
		m_nShortData = 0;
		m_nIntData = 0;
		m_nLongData = 0;
		m_fFloatData = 0.1f;
		m_fDoubleData = 0.2f;
	}
};

trigger the code inspection fix on either of the first two constructors, and the members that this constructor does not initialize are initialized at declaration with default values, leaving the constructor unchanged.

Are you looking for a list of fields to manually initialize for a reason?

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

azur
Senior Member

Germany
46 Posts

Posted - Sep 27 2022 :  08:34:34 AM  Show Profile  Reply with Quote
The inspection fix not worked as espected. Maybe there is a problem with multiple classes in one file.

Try this:
create new MFC-Dialog-Project
in *Dlg.h add a Field like this

HICON m_hIcon;
UINT m_nCount;

switch to *Dlg.cpp
The constructor *Dlg::*Dlg got the yellow inspection mark
try to fix

In my case it's insert curly braces somewhere in the source code:
void CAboutDlg::DoDataExchange(CDataExchange*{} pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


Go to Top of Page

feline
Whole Tomato Software

United Kingdom
17972 Posts

Posted - Sep 28 2022 :  09:47:29 AM  Show Profile  Reply with Quote
Ouch, thank you for the clear description, I am seeing the same problem here. The exact placement of the brackets seems to vary a bit, but the general problem is very clear:

case=148676

Now to see if I can make a really small test case that shows the problem...

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

azur
Senior Member

Germany
46 Posts

Posted - Sep 28 2022 :  10:06:28 AM  Show Profile  Reply with Quote
Thanks for working on this issue.

Perhaps a query with the affected field(s) can be placed before the fix?
If I already have a constructor with a lot of assignments, I might want to add the missing field(s) myself. Otherwise, the VA fix might give me a mixture of initializations in the declaration (H) and implementation (CPP).

Go to Top of Page

feline
Whole Tomato Software

United Kingdom
17972 Posts

Posted - Sep 29 2022 :  12:51:06 PM  Show Profile  Reply with Quote
The trigger seems to be something in the project structure, not the code in the Dlg files. I have simplified the Dlg files down to basically nothing and still get the problem. Very strange, but at least it is a clue. Thank you again for reporting this nasty bug.

As for knowing what is going to happen, we are considering showing a preview of the code change that code inspection will create:

case=104512

which would help here. When this code inspection is working correctly the code edit will always be where the class members are declared, so all of the edits will occur together, only inside the class declaration, leaving all of the constructors untouched.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2021 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000