Author |
Topic |
|
Alexey.Malov
New Member
Russia
4 Posts |
Posted - Jun 09 2017 : 4:57:53 PM
|
In our code base we use the following recommendation from c++ core guidelines: 'C.128: Virtual functions should specify exactly one of virtual, override, or final' https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rh-override
class ISomeInterface
{
public:
virtual ~ISomeInterface() = default;
virtual void Food() = 0;
};
class SomeClass : public ISomeInterface
{
public:
void Foo()override; // no need to add 'virtual' since 'override' can be applied to virtual methods only
};
Currently, Visual Assist adds both 'virtual' and 'override' options when implementing virtual method, so we have to remove 'virtual' keyword manually for each auto-generated method.
It would be great if there was an option to generate virtual method without 'virtual' keyword (only with override). |
|
holedigger
Whole Tomato Software
145 Posts |
Posted - Jun 10 2017 : 02:14:28 AM
|
Good news, there is an option for this, but we haven't exposed UI for it yet, so you'll need to edit the registry.
Close all instances of Visual Studio, then use regedit to find key: HKEY_CURRENT_USER\Software\Whole Tomato\Visual Assist X\VANet{IDE_VER}\CodeInspections
The default value for CheckerOptions is "modernize-use-override.VirtualHandling=insert"
Change "insert" to "remove", and you should get the behavior you're looking for. There are three options: "insert" = add virtual if not present "remove" = remove virtual if present "keep" = don't add it, but don't remove it either
Personally, I like having both 'virtual' and 'override', but the Core Guidelines do say to remove the virtual, so we'll probably change the default to "remove".
Note: these registry settings will be changing in upcoming builds, but not before we add UI to change them in our options dialog.
|
Whole Tomato Software |
|
|
Alexey.Malov
New Member
Russia
4 Posts |
Posted - Jun 13 2017 : 05:54:58 AM
|
Hmm. It seems that we are talking about different things. At least, this option does not affect the behavior of 'Implement Virtual Methods' refactoring function.
I was talking about the behavior of "Implement Virtual Methods..." refactoring option.
When I have an interface
class ISomeInterface
{
public:
virtual ~ISomeInterface() = default;
virtual void Food() = 0;
};
and want to implement its methods in a some class:
class SomeClass : public ISomeInterface
{
public:
};
I right click on the class name and choose Quick Actions and Refactorings (VA)->Implement Virtual Methods. What I want is to generate virtual methods without virtual keyword (leaving only override). This would simplify to use one coding style without need to manually remove 'virtual' from auto-generated code. |
Edited by - Alexey.Malov on Jun 13 2017 05:55:42 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Jun 13 2017 : 09:15:32 AM
|
Apologies for the confusion, the registry key is for the new Code Inspection features, not the older refactoring command. We are considering adding a setting to leave off the virtual keyword when the override keyword is being used:
case=85265
which I think is what you are looking for here. Unfortunately there is no way to do this automatically yet. |
zen is the art of being at one with the two'ness |
|
|
MrDoomMaster
Tomato Guru
251 Posts |
Posted - Mar 13 2018 : 10:09:26 AM
|
I'd like to bump this since it's been a year and I also would love the ability to turn off 'virtual' keyword when implementing base class virtual methods through the refactoring menu. Any updates on progress this past year? This seems like a relatively simple addition. Is it just a low priority and that is why it hasn't been done yet? |
|
|
feline
Whole Tomato Software
United Kingdom
19021 Posts |
Posted - Mar 13 2018 : 3:57:36 PM
|
This is relatively low priority, but it is now being looked at, and we hope to add this in the next few builds of VA.
As always, it is a case of balancing bug fixes with new features and other changes. Never an easy task. |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|