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 - issue with default constructor

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

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

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
tony.riviere Posted - Aug 23 2017 : 07:16:49 AM
Hello,

I have an issue in the following case:

template<typename T>
class Proxy : public std::unique_ptr<T>
{
public:

// Note: both cases are compiling

#if 1
	// Wrong, suggestion (see below) -> compilation error after applying fix
	using BaseClass = std::unique_ptr<T>; // typedef
 	using BaseClass::unique_ptr; // using unique_ptr constructor
#else
	// OK, no suggestion
	using std::unique_ptr<T>::unique_ptr; // using unique_ptr constructor
#endif
};


class MyClass
{
public:
	MyClass();

private:
	class MyClassImpl;
	Proxy<MyClassImpl> m_Impl;
};

class MyClass::MyClassImpl { };

MyClass::MyClass()
	: m_Impl(new MyClassImpl())
{} // Suggestion here (when #if 1): "Default constructor body can be replaced with '= default'
// This suggestion shouldn't happen at all in any cases

/*
// Replaced by:

MyClass::MyClass()
	: m_Impl(new MyClassImpl())
= default; // Compilation error: expecting {}

*/
5   L A T E S T    R E P L I E S    (Newest First)
tony.riviere Posted - Aug 29 2017 : 09:41:12 AM
Correct.
using BaseClass::BaseClass;
does remove the suggestion.
Didn't know why I didn't use it directly. Maybe I thought it was expanding to something like
using std::unique_ptr<T>::std::unique_ptr<T>
which didn't make sense.
Thanks :)
holedigger Posted - Aug 25 2017 : 5:54:35 PM
In your example, change:
using BaseClass::unique_ptr;
to:
using BaseClass::BaseClass;

This fixes the parsing issue, and correctly removes the underlining.
holedigger Posted - Aug 25 2017 : 2:54:35 PM
Yes, it is a more general problem (case=109725) which is caused when there are compile errors, usually because a header doesn't #include all of its dependencies. When you moved the code to the .cpp, then those dependencies much have been included.

Your special case is interesting because it compiles happily with MSVC and GCC, but not Clang (which powers our code inspections). I've been researching workarounds.
tony.riviere Posted - Aug 25 2017 : 04:47:54 AM
It's sounds like a more general issue than the "special" case I mentioned earlier.
Here is another simpler case but the behavior is quite strange: if the code is in .cpp file nothing happen, but if the code is in .h file, then it suggests to replace the default body constructor.

class HtmlTag
{
public:

	HtmlTag(const std::string& iTagName) {}
};

class Head : public HtmlTag
{
public:

	Head()
		: HtmlTag("head")
	{} // Suggest to replace the body by '=default', only if the code is in a header file
};
holedigger Posted - Aug 24 2017 : 02:16:04 AM
Thanks, Tony. I've reproduced the problem and opened case=110568.

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