Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Code Inspection "ctor not initialize all fields"

You must be registered to post a reply.
Click here to register.

Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji

Forum code is on.
Html is off.

Check to subscribe to this topic.

T O P I C    R E V I E W
azur Posted - Sep 27 2022 : 04:01:27 AM
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.

5   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Sep 29 2022 : 12:51:06 PM
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:


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.
azur Posted - Sep 28 2022 : 10:06:28 AM
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).

feline Posted - Sep 28 2022 : 09:47:29 AM
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:


Now to see if I can make a really small test case that shows the problem...
azur Posted - Sep 27 2022 : 08:34:34 AM
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)

feline Posted - Sep 27 2022 : 07:33:50 AM
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?

© 2021 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000