vgvassilev / clad

clad -- automatic differentiation for C/C++
GNU Lesser General Public License v3.0
280 stars 123 forks source link

Static qualifier is dropped when differentiating methods with out-of-line definitions in forward mode #951

Closed PetroZarytskyi closed 3 months ago

PetroZarytskyi commented 3 months ago

Reproducer:

/// The original code
class A {
  public:
  static double fun(double x);
};

double A::fun(double x) {
  return x;
}

int main() {
  clad::differentiate(A::fun);
  return 0;
}

The bit of code above is differentiated as

/// The differentiated code
double fun_darg0(double x) {      // <-- Notice: no static qualifier
    double _d_x = 1;
    return _d_x;
}

Whereas using an in-line definition

/// The original code
class A {
  public:
  static double fun(double x) {
    return x;
  }
};

int main() {
  clad::differentiate(A::fun);
  return 0;
}

results in the expected behavior

/// The differentiated code
static double fun_darg0(double x) {
    double _d_x = 1;
    return _d_x;
}