Issue 241335
Summary Add -Wunused-parameter sub-diagnostic for virtual functions and overrides
Labels clang:diagnostics
Assignees
Reporter nikic
    `-Wunused-parameter` currently warns in this situation:
```c++
class A {
    // warning: unused parameter 'MayOrMayNotBeNeeded'
    virtual bool isFoo(int MayOrMayNotBeNeeded) {
        return false;
    }
};

class B : A {
 // warning: unused parameter 'MayOrMayNotBeNeeded'
    bool isFoo(int MayOrMayNotBeNeeded) override {
        // Is currently always foo.
 return true;
    }
};

class C : A {
    bool isFoo(int MayOrMayNotBeNeeded) override {
        // Is sometimes foo.
        return MayOrMayNotBeNeeded != 0;
    }
};
```

Unlike for most other functions, for virtual functions and virtual function overrides, unused parameters are both common and intentional. The `-Wunused-parameter` warning is usually a false-positive for them, and suppressing it may not be an improvement to code quality (e.g. removing the parameter name from the `virtual` function may no longer make it self-documenting).

It would be nice to split this case off into a separate diagnostic (like `-Wunused-parameter-in-hook`) so that it's possible to enable most `-Wunused-parameter` warnings while disabling these specific cases. This is particularly relevant for code bases like LLVM and came up in https://discourse.llvm.org/t/rfc-phasing-out-the-wno-unused-parameter-suppression-when-building/92744.

There are variants of this pattern, like callbacks passed to arguments, but I think they may be harder to reliably detect. Another is CRTP.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to