使用boost :: variant

时间:2018-05-22 12:06:28

标签: llvm-clang boost-variant clang-tidy

当在下面发布的这个最小的例子上运行clang-tidy时,我从clang-tidy(最后的完整错误跟踪)得到(imho)误报错误

Value assigned to field 'id' in implicit constructor is garbage or undefined [clang-analyzer-core.uninitialized.Assign]

代码除了将boost::variant分配给两个值中的一个之外什么都不做。如果我用Size(const Size& sz) = default;替换复制构造函数,则错误消失了。但是,我不能这样做,因为实际代码中的大小是cv::Size

即使它可能不尽如人意,但我也没有看到任何错误。 如果我弄错了,铿锵有力或提升,有人会指出我的方向。

#include <boost/variant.hpp>

class Size
{
public:
  Size() = default;
  Size(const Size &sz) : width(sz.width) {}
  int width{0};
};

struct B {
  Size size;
};

struct A {
  Size size;
  uint32_t id{0};
};

int main() {
  using T = boost::variant<A, B>;
  T config = B();
}

我正在跑步:

  • clang-tools-extra commit 50fe75789f08b96284d2c14cb6583b3783c74460
  • llvm commit afb8c1fed21eb4848d86f2d28e9cb3afc​​fbb2656
  • boost 1.67

完整错误转储:

test_variant.cc:15:8: warning: Value assigned to field 'id' in implicit constructor is garbage or undefined [clang-analyzer-core.uninitialized.Assign]
struct A {
       ^
test_variant.cc:22:5: note: Calling move constructor for 'variant'
  T config = B();
    ^
libraries/boost/include/boost/variant/variant.hpp:1880:9: note: Calling 'variant::internal_apply_visitor'
        operand.internal_apply_visitor(visitor);
        ^
libraries/boost/include/boost/variant/variant.hpp:2466:16: note: Calling 'variant::internal_apply_visitor_impl'
        return internal_apply_visitor_impl(
               ^
libraries/boost/include/boost/variant/variant.hpp:2452:16: note: Calling 'visitation_impl'
        return detail::variant::visitation_impl(
               ^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:225:5: note: Control jumps to 'case 0:'  at line 238
    switch (logical_which)
    ^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:240:11: note: Calling 'visitation_impl_invoke'
        , BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
          ^
libraries/boost/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))
                         ^
libraries/boost/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)
                               ^
libraries/boost/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 21 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
libraries/boost/include/boost/preprocessor/repetition/repeat.hpp:53:56: 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)
                                                       ^
libraries/boost/include/boost/preprocessor/repetition/repeat.hpp:52:36: note: expanded from macro 'BOOST_PP_REPEAT_1_1'
# define BOOST_PP_REPEAT_1_1(m, d) m(2, 0, d)
                                   ^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:231:16: note: expanded from macro 'BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE'
        return (visitation_impl_invoke)( \
               ^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:154:12: note: Calling 'visitation_impl_invoke_impl'
    return (visitation_impl_invoke_impl)(
           ^
libraries/boost/include/boost/variant/detail/visitation_impl.hpp:112:12: note: Calling 'move_into::internal_visit'
    return visitor.internal_visit(
           ^
libraries/boost/include/boost/variant/variant.hpp:507:23: note: Calling implicit move constructor for 'A'
        new(storage_) T(::boost::detail::variant::move(operand));
                      ^
test_variant.cc:15:8: note: Value assigned to field 'id' in implicit constructor is garbage or undefined
struct A {

0 个答案:

没有答案