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 - issue with default constructor
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tony.riviere
Ketchup Master

France
58 Posts

Posted - Aug 23 2017 :  07:16:49 AM  Show Profile  Reply with Quote
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 {}

*/

holedigger
Whole Tomato Software

145 Posts

Posted - Aug 24 2017 :  02:16:04 AM  Show Profile  Reply with Quote
Thanks, Tony. I've reproduced the problem and opened case=110568.

Whole Tomato Software
Go to Top of Page

tony.riviere
Ketchup Master

France
58 Posts

Posted - Aug 25 2017 :  04:47:54 AM  Show Profile  Reply with Quote
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
};
Go to Top of Page

holedigger
Whole Tomato Software

145 Posts

Posted - Aug 25 2017 :  2:54:35 PM  Show Profile  Reply with Quote
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.

Whole Tomato Software
Go to Top of Page

holedigger
Whole Tomato Software

145 Posts

Posted - Aug 25 2017 :  5:54:35 PM  Show Profile  Reply with Quote
In your example, change:
using BaseClass::unique_ptr;
to:
using BaseClass::BaseClass;

This fixes the parsing issue, and correctly removes the underlining.

Whole Tomato Software
Go to Top of Page

tony.riviere
Ketchup Master

France
58 Posts

Posted - Aug 29 2017 :  09:41:12 AM  Show Profile  Reply with Quote
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 :)

Edited by - tony.riviere on Aug 29 2017 09:42:48 AM
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