I know this question.
However I have a compiler warning which mentions this
which makes a bit different from the question above.
As the above question's answer clearly states that the attribute in the warning is defined with
attribute((nonnull));
Consider this class:
class ReferenceCounter {
public:
ReferenceCounter(void) : count_(0) {
}
ReferenceCounter& operator=(const ReferenceCounter& other_) {
if (this != &other_) {
count_ = other_.count_;
}
return *this;
}
void increment(void) {
++count_;
}
int decrement(void) {
return this == NULL ? 0 : --count_;
}
private:
int count_;
};
Compiler warns for the return this == NULL ? 0 : --count_;
line with
warning: nonnull argument ‘this’ compared to NULL
Where is "this" decided to be nonnull here?
Note: ReferenceCounter is used only in one place as a pointer:
ReferenceCounter* r;
Which makes possible to be NULL so I don't understand why the compiler complains about this particular check and want to
- understand
- correct
Please don't shoot me about this code, it's not mine, just I'm forced to use it.