<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - UndefReturn false positive with variant of optionals"
   href="https://bugs.llvm.org/show_bug.cgi?id=41334">41334</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>UndefReturn false positive with variant of optionals
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>8.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>alexander.grund@tu-dresden.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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*
<span class="quote">>(rhs_storage_));</span >
                      ^
/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*
<span class="quote">>(rhs_storage_));</span >
        ^
/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 ; }</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>