[cfe-dev] Is there a warning when using the wrong types that do not have the same underlying type on all systems?

Ruben Van Boxem vanboxem.ruben at gmail.com
Mon Nov 7 05:27:32 PST 2011


Often, one sees code like this:

string s;
size_t length_of_string = s.size();

Although this is correct, and should not bite you in the buttocks on any
common implemenetation, it's not *pedantically* correct and fully portable.
The return type of string::size is by definition string::size_type, and
although the common existing implementations use size_t, these two don't
have to be the same type, and could result in unexpected weirdness.
Is there any warning available (or uberhaupt implementable) in Clang that
checks these kinds of implementation-dependent conversions, and perhaps
suggest the type better suited (or a static_cast to the user's type)?

I understand this is pure pedantry and of little practical use (especially
the string::size() case), but I would figure there could be larger bugs
exposed in a more general case where there is an unnecessary implicit
conversion. (although that word would mean these shouldn't be warned for at
all, as it's a predefined language feature).

Thanks!

Ruben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20111107/91044c6b/attachment.html>


More information about the cfe-dev mailing list