问题
How to make Resharper syntax-highlight non-exist dependent name (e.g. member field) as error?
In the below code, I expect a.nonMember
to has red squiggle.
template<class T>class Test1{
public: int member;
};
template<class T>void f(){
Test1<T> a;
a.member=5;
a.nonMember=8; //<-- expect red squiggle here
}
However, there is no such red squiggle.
I believe there must be such a feature,
because Resharper can already recognize all fields of Test1<>
correctly (shown in the following image).
回答1:
Resharper is not wrong. It has no way to know such a member doesn't exist, because the member is dependent, and so could exist.
template<>
class Test1<int> {
public: int nonMember;
};
What should be highlighted now when we can call f<int>()
? The possibility of specializations means that making such diagnostics is intractable for dependent names.
来源:https://stackoverflow.com/questions/54900697/red-squiggle-non-existing-dependent-name-e-g-ctnonmember-as-error