5

Is there any compiler option that allows you to get a warning when you try to assign to temporary object?

Example:

struct S {
    S op() { return S(); }
};

int main() {
    S s;
    s.op() = s; // assign to temporary. Wants to warn here.
}

I know that you can declare the return type of op as const to prevent such a situation, but now I'm interested in is the compiler options only.

You can use any popular modern compiler.

αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71

1 Answers1

0

The compiler may not be able to tell useful side effects.

Compilers do warn for

int test( S & data );

test( S.op());
mksteve
  • 12,614
  • 3
  • 28
  • 50