In Xcode 3.2 under iPhone-SDK 3.1, how do I avoid “Dead store” error from CLANG analyzer?
-
07-07-2019 - |
Question
I just upgraded to Xcode 3.2 and am using the Build and Analyze feature to check old code for errors.
While doing something I thought was innocuous, I get this error:
"Dead store: Value stored to 'newBook' during it's initialization is never read in SpellTest.m"
#define kSpellBookFilename @"TestBookSaver"
-(void)testBookLoadFromDisk;
{
// restore object from disk
SpellBook *newBook = [[[SpellBook alloc] init] autorelease];
newBook = [NSKeyedUnarchiver unarchiveObjectWithFile:kSpellBookFilename];
// show restored object
NSLog(@"archived copy %@", newBook);
}
Am I initializing this object wrong or is this a false positive?
Solution
It is a dead store. Why do you even initialize a new SpellBook object in the first code line when you just throw it away in the next line? Just remove the first line (and move the type declaration to the second one).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow