This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Diagnose null inputs in std::string using _LIBCPP_DIAGNOSE_WARNING
Needs ReviewPublic

Authored by EricWF on Jan 13 2017, 5:29 PM.

Details

Reviewers
mclow.lists
Summary

This patch uses diagnose_if to attempt to catch null inputs in std::string. Note that unlike __attribute__((non_null)) diagnose_if does not affect codegen.

Diff Detail

Event Timeline

EricWF updated this revision to Diff 84410.Jan 13 2017, 5:29 PM
EricWF retitled this revision from to [libc++] Diagnose null inputs in std::string using _LIBCPP_DIAGNOSE_WARNING.
EricWF updated this object.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.

would it be better to internally treat attribute((non_null)) like diagnose_if ? then you get all the warnings for free?

would it be better to internally treat attribute((non_null)) like diagnose_if ? then you get all the warnings for free?

There were previous objections about using non_null within libc++ due to the affect on code gen. That's why I choose to use diagose_if here.
However the previous objections weren't about std::string, so maybe the consensus would be different here? I'll ping @mclow.lists about this.

Note: Some of these non-null diagnostics depend on the second condition size > 0, which can't be done with non-null.