[llvm-bugs] [Bug 41334] New: UndefReturn false positive with variant of optionals
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Apr 1 08:52:31 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=41334
Bug ID: 41334
Summary: UndefReturn false positive with variant of optionals
Product: clang
Version: 8.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Static Analyzer
Assignee: dcoughlin at apple.com
Reporter: alexander.grund at tu-dresden.de
CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org
I'm getting a false positive that a returned value is undefined.
Code:
#include <boost/optional.hpp>
#include <boost/variant.hpp>
struct Foo
{
boost::optional<int> startTime;
};
struct Bar
{
bool isPinging;
boost::optional<int> startTime;
};
boost::variant<Foo, Bar> state_;
void foo(int i){
Foo state;
state_ = std::move(state);
}
int main(int argc, char** argv){
foo(argc);
}
Messages:
clang-tidy-8 -p . -checks="-*,clang-analyzer-core.uninitialized.UndefReturn"
main.cpp
2 warnings generated.
/usr/include/boost/optional/optional.hpp:472:35: warning: Undefined or garbage
value returned to caller [clang-analyzer-core.uninitialized.UndefReturn]
bool is_initialized() const { return m_initialized ; }
^
/home/alex/Schreibtisch/cmakeTest/main.cpp:20:3: note: Calling 'foo'
foo(argc);
^
/home/alex/Schreibtisch/cmakeTest/main.cpp:17:5: note: Calling
'variant::operator='
state_ = std::move(state);
^
/usr/include/boost/variant/variant.hpp:2125:9: note: Calling
'variant::move_assign'
move_assign( detail::variant::move(rhs) );
^
/usr/include/boost/variant/variant.hpp:2104:9: note: Taking true branch
if (this->apply_visitor(direct_move) == false)
^
/usr/include/boost/variant/variant.hpp:2112:21: note: Calling constructor for
'variant<Foo, Bar>'
variant temp( detail::variant::move(rhs) );
^
/usr/include/boost/variant/variant.hpp:1732:9: note: Calling
'variant::convert_construct'
convert_construct( detail::variant::move(operand), 1L);
^
/usr/include/boost/variant/variant.hpp:1555:15: note: Calling
'initializer_node::initialize'
initializer::initialize(
^
/usr/include/boost/variant/detail/initializer.hpp:119:30: note: Assuming
'value' is 0
BOOST_ASSERT(!is_reference_content_t::value);
^
/usr/include/boost/assert.hpp:56:36: note: expanded from macro 'BOOST_ASSERT'
# define BOOST_ASSERT(expr) assert(expr)
^
/usr/include/assert.h:89:5: note: expanded from macro 'assert'
((expr) \
^
/usr/include/boost/variant/detail/initializer.hpp:119:17: note: '?' condition
is true
BOOST_ASSERT(!is_reference_content_t::value);
^
/usr/include/boost/assert.hpp:56:29: note: expanded from macro 'BOOST_ASSERT'
# define BOOST_ASSERT(expr) assert(expr)
^
/usr/include/assert.h:89:4: note: expanded from macro 'assert'
((expr) \
^
/usr/include/boost/variant/detail/initializer.hpp:122:17: note: Calling
'operator new'
new(dest) value_T( boost::detail::variant::move(operand) );
^
/usr/include/boost/variant/detail/initializer.hpp:122:17: note: Returning from
'operator new'
/usr/include/boost/variant/variant.hpp:1555:15: note: Returning from
'initializer_node::initialize'
initializer::initialize(
^
/usr/include/boost/variant/variant.hpp:1732:9: note: Returning from
'variant::convert_construct'
convert_construct( detail::variant::move(operand), 1L);
^
/usr/include/boost/variant/variant.hpp:2112:21: note: Returning from
constructor for 'variant<Foo, Bar>'
variant temp( detail::variant::move(rhs) );
^
/usr/include/boost/variant/variant.hpp:2113:29: note: Calling
'move<boost::variant<Foo, Bar> &>'
variant_assign( detail::variant::move(temp) );
^
/usr/include/boost/variant/variant.hpp:2113:29: note: Returning from
'move<boost::variant<Foo, Bar> &>'
/usr/include/boost/variant/variant.hpp:2113:13: note: Calling
'variant::variant_assign'
variant_assign( detail::variant::move(temp) );
^
/usr/include/boost/variant/variant.hpp:2063:13: note: Assuming the condition is
true
if (which_ == rhs.which_)
^
/usr/include/boost/variant/variant.hpp:2063:9: note: Taking true branch
if (which_ == rhs.which_)
^
/usr/include/boost/variant/variant.hpp:2066:43: note: Calling constructor for
'move_storage'
detail::variant::move_storage visitor(rhs.storage_.address());
^
/usr/include/boost/variant/variant.hpp:2066:43: note: Returning from
constructor for 'move_storage'
/usr/include/boost/variant/variant.hpp:2067:13: note: Calling
'variant::internal_apply_visitor'
this->internal_apply_visitor(visitor);
^
/usr/include/boost/variant/variant.hpp:2332:16: note: Calling
'variant::internal_apply_visitor_impl'
return internal_apply_visitor_impl(
^
/usr/include/boost/variant/variant.hpp:2318:16: note: Calling
'visitation_impl<mpl_::int_<0>,
boost::detail::variant::visitation_impl_step<boost::mpl::l_iter<boost::mpl::l_item<mpl_::long_<2>,
Foo, boost::mpl::l_item<mpl_::long_<1>, Bar, boost::mpl::l_end> > >,
boost::mpl::l_iter<boost::mpl::l_end> >, boost::detail::variant::move_storage,
void *, boost::variant<Foo, Bar>::has_fallback_type_>'
return detail::variant::visitation_impl(
^
/usr/include/boost/variant/detail/visitation_impl.hpp:225:5: note: Control
jumps to 'case 1:' at line 238
switch (logical_which)
^
/usr/include/boost/variant/detail/visitation_impl.hpp:240:11: note: Calling
'visitation_impl_invoke<boost::detail::variant::move_storage, void *, Bar,
boost::variant<Foo, Bar>::has_fallback_type_>'
, BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
^
/usr/include/boost/preprocessor/repetition/repeat.hpp:29:26: note: expanded
from macro 'BOOST_PP_REPEAT'
# define BOOST_PP_REPEAT BOOST_PP_CAT(BOOST_PP_REPEAT_,
BOOST_PP_AUTO_REC(BOOST_PP_REPEAT_P, 4))
^
/usr/include/boost/preprocessor/cat.hpp:22:32: note: expanded from macro
'BOOST_PP_CAT'
# define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
^
/usr/include/boost/preprocessor/cat.hpp:29:34: note: expanded from macro
'BOOST_PP_CAT_I'
# define BOOST_PP_CAT_I(a, b) a ## b
^
note: (skipping 20 expansions in backtrace; use -fmacro-backtrace-limit=0 to
see all)
/usr/include/boost/preprocessor/repetition/repeat.hpp:54:56: note: expanded
from macro 'BOOST_PP_REPEAT_1_3'
# define BOOST_PP_REPEAT_1_3(m, d) BOOST_PP_REPEAT_1_2(m, d) m(2, 2, d)
^
/usr/include/boost/preprocessor/repetition/repeat.hpp:53:62: note: expanded
from macro 'BOOST_PP_REPEAT_1_2'
# define BOOST_PP_REPEAT_1_2(m, d) BOOST_PP_REPEAT_1_1(m, d) m(2, 1, d)
^
/usr/include/boost/variant/detail/visitation_impl.hpp:231:16: note: expanded
from macro 'BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE'
return (visitation_impl_invoke)( \
^
/usr/include/boost/variant/detail/visitation_impl.hpp:154:12: note: Calling
'visitation_impl_invoke_impl<boost::detail::variant::move_storage, void *,
Bar>'
return (visitation_impl_invoke_impl)(
^
/usr/include/boost/variant/detail/visitation_impl.hpp:112:12: note: Calling
'move_storage::internal_visit'
return visitor.internal_visit(
^
/usr/include/boost/variant/variant.hpp:551:23: note: Calling 'move<Bar &>'
lhs_content = ::boost::detail::variant::move(*static_cast<T*
>(rhs_storage_));
^
/usr/include/boost/variant/variant.hpp:551:23: note: Returning from 'move<Bar
&>'
/usr/include/boost/variant/variant.hpp:551:9: note: Calling implicit move
assignment operator for 'Bar'
lhs_content = ::boost::detail::variant::move(*static_cast<T*
>(rhs_storage_));
^
/usr/include/boost/variant/variant.hpp:551:9: note: Calling move assignment
operator for 'optional<int>'
/usr/include/boost/optional/optional.hpp:933:9: note: Calling
'optional_base::assign'
this->assign( static_cast<base &&>(rhs) ) ;
^
/usr/include/boost/optional/optional.hpp:353:11: note: Assuming the condition
is false
if (is_initialized())
^
/usr/include/boost/optional/optional.hpp:353:7: note: Taking false branch
if (is_initialized())
^
/usr/include/boost/optional/optional.hpp:361:14: note: Calling
'optional_base::is_initialized'
if ( rhs.is_initialized() )
^
/usr/include/boost/optional/optional.hpp:472:35: note: Undefined or garbage
value returned to caller
bool is_initialized() const { return m_initialized ; }
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190401/78494b74/attachment-0001.html>
More information about the llvm-bugs
mailing list