This is a continuation of https://reviews.llvm.org/D44844 and a potential fix for https://bugs.llvm.org/show_bug.cgi?id=36880.
This fix follows the specification in http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html 8.1.5.2 paragraph 7.
template <typename A>
class Variant {
public:
Variant() {
[this](auto value) { Construct(value); }(5); // false positive warning about "this" capture unused.
}
template <typename Arg>
void Construct(Arg value) {}
};
int main() {
Variant<int> v;
return 0;
}Whenever we see a UnresolvedMemberExpr, we always mark a this capture ODR-used, even if later on it may be resolved to a static member function. The trade-off of this fix is that it will leads to false negative in the following case:
template <typename A>
class OverloadedMixFalseNegative {
public:
OverloadedMixFalseNegative() {
[this](auto value) { Construct(value); }(5); // warning disappears but should happen
}
static void Construct(int value) {}
void Construct(float value) {}
};
LLVM style is not to use {} for single statement bodies.