The "Pass-by-value argument in message expression is undefined" static analyzer error explained.
I was running the LLVM/Clang Static Analyzer on my iPhone project today and got the following error:
"Pass-by-value argument in message expression is undefined"
That means as much to me as "blah blah blah blee is undefined" so I looked at the code that was triggering it. Here's a simplified version:
NSString *x;
if (someExpression) {
x = someThing;
}
NSDictionary *someDict = [NSDictionary dictionaryWithObjectsAndKeys: x, kSomeKey, ..., nil];
What the analyzer is saying here is that it cannot know for sure that x will be assigned a value. The fix is simple: assign x a default value while declaring it:
NSString *x = @"some default value";
Tada, error gone!
(Note: in my actual app, I was iterating over a data structure and populating the default values of user preferences in NSUserDefaults – you will probably run into this in a similar situation involving a loop.)
Comments
by Danny Greg on 2009-12-09 14:31:27
by Nikolay on 2010-04-16 14:00:55
by Jim on 2010-10-28 22:31:31
by swati on 2011-01-13 13:30:11
by iPhan on 2010-09-13 14:49:29
by Matthias on 2011-02-23 15:07:44
by Petar on 2011-06-08 19:30:46