0

I'm working on a large project and I've updated a method that's used by almost all parts of the system; the method now takes another parameter. I wanted to make the new parameter optional so that I don't have to go and update everyone else's code to make use of it, so I provide a default parameter.

Is there any way I can emit a compiler warning to state that relying on the default parameter is deprecated, only if they're relying on it?

Lynden Shields
  • 1,062
  • 1
  • 10
  • 27
  • 1
    There is no standard way to emit a compiler warning for deprecated anything, let alone to this specificity. I've only seen one compiler that even does it: MSVC. – Edward Strange Dec 11 '12 at 00:30
  • I've been looking into that a bit also & found a question about it: http://stackoverflow.com/q/295120/78823 – Lynden Shields Dec 11 '12 at 00:56

1 Answers1

6

Instead of using a default parameter, you could try using an overloaded function, one that has the extra parameter and one that doesn't, and mark the one without the extra parameter as deprecated. It can call through to the new function, passing in whatever default you want.

Lily Ballard
  • 182,031
  • 33
  • 381
  • 347
  • I'm having some trouble now, the warning only comes up when the function is compiled, but I want it to come up when the function is called (I don't mean at run time, I mean when another file mentions the function) – Lynden Shields Dec 11 '12 at 00:54
  • 1
    @LyndenShields: How did you trigger the warning? Using `__attribute__((deprecated("Use the other version of this function please")))` ([supported by clang](http://clang.llvm.org/docs/LanguageExtensions.html#deprecated), not sure about gcc) should only warn on use. – Lily Ballard Dec 11 '12 at 00:58