Why does the Clang Static Analyzer (CSA) output the following message:
Although the value stored to ‘self’ is
used in the enclosing expression, the
value is never actually read from
‘self’
for the following method:
- (id)init
{
return (self = [super initWithStyle:UITableViewStyleGrouped]);
}
The code works as expected, so I’m wondering whether the code is incorrect from a technical point-of-view, this is a bug within CSA or I’m simply missing something very obvious.
FYI, I’m using this pattern because I don’t want the class creating an instance of this class to be able to specify the table style.
A more “proper” way to do this would be as follows:
And it should satisfy the static analyzer
edit:
My best guess as to why Clang doesn’t like that line:
When you write
(self = [super initWithStyle:UITableViewStyleGrouped]), the result of theinitcall is stored into a temporary variable, which is then copied intoself, and then it is that temporary variable that is actually returned from the method.Although this is perfectly legal and normal behaviour (and will not break your app), the static analyzer (correctly) notices that the value stored in
selfis never actually read.To illustrate, the following code:
Throws the same static analyzer error.