https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93999

            Bug ID: 93999
           Summary: Maybe a misleading warning
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
  Target Milestone: ---

We may emit a misleading warning based on:
https://github.com/godotengine/godot/pull/36393

$ cat grid.ii
class A;
template <class T, class... P>
void call_with_variant_args_helper(void (T::*p_method)(), int p_args) {
  A *p_instance;
  (p_instance->*p_method)(P(p_args)...);
}
template <class T> void call_with_variant_args(void (T::*)()) {
  call_with_variant_args_helper<A>;
}
template <class T> class CallableCustomMethodPointer {
  struct {
    void (T::*method)();
  } data;

public:
  virtual void m_fn1() { call_with_variant_args(data.method); }
  CallableCustomMethodPointer(A *, void (T::*)()) {}
};
template <class T>
void create_custom_callable_function_pointer(A *p_instance, const char *,
                                             void (T::*p_method)()) {
  CallableCustomMethodPointer(p_instance, p_method);
}
class A {
  void m_fn2();
  A();
};
A::A() { create_custom_callable_function_pointer(this, "", &A::m_fn2); }

$ g++ grid.ii -c -Wunused-but-set-parameter -Werror -std=c++17 -fmax-errors=1
grid.ii: In instantiation of ‘void call_with_variant_args_helper(void (T::*)(),
int) [with T = A; P = {}]’:
grid.ii:8:3:   required from ‘void call_with_variant_args(void (T::*)()) [with
T = A]’
grid.ii:16:48:   required from ‘void CallableCustomMethodPointer<T>::m_fn1()
[with T = A]’
grid.ii:16:16:   required from here
grid.ii:3:63: error: parameter ‘p_args’ set but not used
[-Werror=unused-but-set-parameter]
    3 | void call_with_variant_args_helper(void (T::*p_method)(), int p_args) {
      |                                                           ~~~~^~~~~~
cc1plus: all warnings being treated as errors

Reply via email to