Re:C++ at Google: Here Be Dragons
by chandlerc on Monday May 23, 2011 @08:14PM
(#2578149)
GCC definitely has a warning for 0.5 -> int (likely -Wconversion, but I've not checked). It also has a warning for setting a pointer to "false" (-Wconversion-null). However, turning that warning on in a codebase where every warning breaks the build was challenging because of false positives. We're able to remove false positives and narrow the scope of the warning to just the buggy code in many cases with Clang, and that allows us to turn these warnings on much more aggressively.
[ Parent
| on HN ]
Isn't the real bug in the example where the bool was assigned to the pointer that a pointer was used where it should have been a reference?
Re:C++ at Google: Here Be Dragons
by Hemospectrum on Tuesday May 24, 2011 @12:24PM
(#2580476)
Google's C++ style guide discourages the use of references altogether.
When is assigning a pointer to be boolean false intentional and correct?
Most of the cases we ran into were metaprogramming techniques which test whether an expression is a valid null pointer constants. These got innocently applied to 'false' and trigger the warning needlessly.
Re:C++ at Google: Here Be Dragons
by koenigdavidmj on Tuesday May 24, 2011 @05:41PM
(#2581778)
Done that before...had a variable that was formerly an int:
int foo = 0;
But got changed into a non-integral type: Thing foo = 0;
Turns out Thing had a copy constructor roughly like: Thing::Thing(Thing* old)
: field(old->field)
{
}
Needless to say, my program was not very happy.