Open
springmeyer
opened this issue 8 years ago
•
9 comments
I'm attempting to set up clang-tidy to run on codebases using variant. I am consistently seeing most warnings coming from variant. So these need to be addressed here, at the source, by either adding // NOLINT where appropriate or fixing.
@artemp can you please tackle this next week?
Here are the warnings:
```
./include/mapbox/variant.hpp:344:16: warning: Function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
return f(unwrapper::apply(v.template get_unchecked()));
^
test/lambda_overload_test.cpp:122:5: note: Calling 'test_match_singleton'
test_match_singleton();
^
test/lambda_overload_test.cpp:87:5: note: Calling 'variant::match'
singleton.match([](int) {});
^
./include/mapbox/variant.hpp:903:16: note: Calling 'variant::visit'
return variant::visit(*this, ::mapbox::util::make_visitor(std::forward(fs)...));
^
./include/mapbox/variant.hpp:871:16: note: Calling 'dispatcher::apply'
return detail::dispatcher::apply(v, std::forward(f));
^
./include/mapbox/variant.hpp:344:18: note: Calling 'unwrapper::apply'
return f(unwrapper::apply(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:344:18: note: Returning from 'unwrapper::apply'
return f(unwrapper::apply(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:344:16: note: Function call argument is an uninitialized value
return f(unwrapper::apply(v.template get_unchecked()));
^
2 warnings generated.
./include/mapbox/recursive_wrapper.hpp:106:36: warning: Undefined or garbage value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
const T* get_pointer() const { return p_; }
^
test/hashable_test.cpp:157:5: note: Calling 'test_recursive_hashable'
test_recursive_hashable();
^
test/hashable_test.cpp:142:10: note: Calling move constructor for 'variant'
Tree tree = Node{Node{Empty{}, Empty{}}, Empty{}};
^
./include/mapbox/variant.hpp:615:9: note: Calling 'variant_helper::move'
helper_type::move(old.type_index, &old.data, &data);
^
./include/mapbox/variant.hpp:235:9: note: Taking false branch
if (old_type_index == sizeof...(Types))
^
./include/mapbox/variant.hpp:241:13: note: Calling 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:235:9: note: Taking false branch
if (old_type_index == sizeof...(Types))
^
./include/mapbox/variant.hpp:241:13: note: Calling 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:241:13: note: Returning from 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:241:13: note: Returning from 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:615:9: note: Returning from 'variant_helper::move'
helper_type::move(old.type_index, &old.data, &data);
^
test/hashable_test.cpp:142:10: note: Returning from move constructor for 'variant'
Tree tree = Node{Node{Empty{}, Empty{}}, Empty{}};
^
test/hashable_test.cpp:144:9: note: Calling 'hash::operator()'
if (std::hash{}(tree) != ((5 + (5 + (3 + 3))) + 3))
^
./include/mapbox/variant.hpp:1022:16: note: Calling 'apply_visitor'
return ::mapbox::util::apply_visitor(::mapbox::util::detail::hasher{}, v);
^
./include/mapbox/variant.hpp:959:12: note: Calling 'variant::visit'
return V::visit(v, std::forward(f));
^
./include/mapbox/variant.hpp:864:16: note: Calling 'dispatcher::apply_const'
return detail::dispatcher::apply_const(v, std::forward(f));
^
./include/mapbox/variant.hpp:311:9: note: Taking false branch
if (v.template is())
^
./include/mapbox/variant.hpp:317:20: note: Calling 'dispatcher::apply_const'
return dispatcher::apply_const(v, std::forward(f));
^
./include/mapbox/variant.hpp:339:18: note: Calling 'unwrapper::apply_const'
return f(unwrapper::apply_const(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:279:16: note: Calling 'recursive_wrapper::get'
return obj.get();
^
./include/mapbox/recursive_wrapper.hpp:101:17: note: Calling 'recursive_wrapper::get_pointer'
return *get_pointer();
^
./include/mapbox/recursive_wrapper.hpp:106:36: note: Undefined or garbage value returned to caller
const T* get_pointer() const { return p_; }
^
./include/mapbox/variant.hpp:555:16: warning: Function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
return std::hash{}(hashable);
^
test/hashable_test.cpp:153:5: note: Calling 'test_singleton'
test_singleton();
^
test/hashable_test.cpp:17:7: note: Calling move constructor for 'variant'
V singleton = 5;
^
./include/mapbox/variant.hpp:615:9: note: Calling 'variant_helper::move'
helper_type::move(old.type_index, &old.data, &data);
^
./include/mapbox/variant.hpp:235:9: note: Taking false branch
if (old_type_index == sizeof...(Types))
^
./include/mapbox/variant.hpp:241:13: note: Calling 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:241:13: note: Returning from 'variant_helper::move'
variant_helper::move(old_type_index, old_value, new_value);
^
./include/mapbox/variant.hpp:615:9: note: Returning from 'variant_helper::move'
helper_type::move(old.type_index, &old.data, &data);
^
test/hashable_test.cpp:17:7: note: Returning from move constructor for 'variant'
V singleton = 5;
^
test/hashable_test.cpp:19:9: note: Calling 'hash::operator()'
if (std::hash{}(singleton) != std::hash{}(5))
^
./include/mapbox/variant.hpp:1022:16: note: Calling 'apply_visitor'
return ::mapbox::util::apply_visitor(::mapbox::util::detail::hasher{}, v);
^
./include/mapbox/variant.hpp:959:12: note: Calling 'variant::visit'
return V::visit(v, std::forward(f));
^
./include/mapbox/variant.hpp:864:16: note: Calling 'dispatcher::apply_const'
return detail::dispatcher::apply_const(v, std::forward(f));
^
./include/mapbox/variant.hpp:339:18: note: Calling 'unwrapper::apply_const'
return f(unwrapper::apply_const(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:339:18: note: Returning from 'unwrapper::apply_const'
return f(unwrapper::apply_const(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:339:18: note: Passing value via 1st parameter 'hashable'
return f(unwrapper::apply_const(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:339:16: note: Calling 'hasher::operator()'
return f(unwrapper::apply_const(v.template get_unchecked()));
^
./include/mapbox/variant.hpp:555:16: note: Function call argument is an uninitialized value
return std::hash{}(hashable);
```
@artemp your output indicates that only bench_variant.cpp is being checked. Not sure why that is. Mine is checking more .cpp files locally. Can you share the build/compile_commands.json that is on your machine in a gist? Also, for reference, here is my output https://gist.github.com/springmeyer/86c27ec500c81286bd124128b06f6bd8
@artemp Thinking more. The problem is likely that my script to produce compile_commands.json is brittle. It has some minimal regex to try to detect which lines (coming from make) are compile commands: https://github.com/mapbox/variant/blob/bdd45a6aaad0de81f471898dfe958241b618361a/scripts/generate_compile_commands.py#L24
#include <mapbox/variant.hpp>
class Empty {};
inline bool operator==(const Empty&, const Empty&) { return true; }
int main() {
using type = mapbox::util::variant<Empty, int>;
type a;
type b = a;
(void)(a == b);
}