[cfe-commits] [patch] fixit for null-conversion
Douglas Gregor
dgregor at apple.com
Mon Apr 30 09:05:49 PDT 2012
On Apr 29, 2012, at 9:05 PM, David Blaikie wrote:
> Just something I've had lying around for a while - I'm not sure
> whether this meets the fixit bar, presumably the real mistakes people
> make when using NULL is that they were calling the wrong function,
> passing arguments in the wrong order, etc - if they're simply passing
> NULL when they meant 0, that's not really the cause of bugs.
+const char *Sema::getFixItZeroLiteralForType(QualType T) const {
+ const char *Str = getFixItZeroInitializerForType(T);
+ if (!Str)
+ return Str;
+ size_t Len = std::strlen(Str);
+ assert(Len > 3 && "Should be a non-record type init");
+ assert(strncmp(Str, " = ", 3) == 0 && "Should be non-record type init");
+ return Str + 3;
+}
This feels very brittle. At the very least, this needs a comment in getFixItZeroInitializerForType() so that we know to look here each time we change it. getFixItZeroLiteralForType() then needs more assertions so that it is obvious to that future reader what the invariants are. Also, 'Len' isn't needed as a variable, and will cause a warning in a non-asserts build.
- Doug
More information about the cfe-commits
mailing list