boostorg / leaf

Lightweight Error Augmentation Framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BOOST_LEAF_CHECK and extra semicolons

mikezackles opened this issue · comments

BOOST_LEAF_ASSIGN has no enclosing block, but BOOST_LEAF_CHECK does. This seems inconsistent and means that BOOST_LEAF_CHECK(mycoolthing()); results in an extra semicolon (and potentially a warning).

Are you thinking

#define BOOST_LEAF_CHECK(r)\
    static_assert(::boost::leaf::is_result_type<typename std::decay<decltype(r)>::type>::value, "BOOST_LEAF_CHECK requires a result type");\
    auto && BOOST_LEAF_TMP = r;\
    if( BOOST_LEAF_TMP )\
        ;\
    else\
        return BOOST_LEAF_TMP.error()

?

Yes, something along those lines, I think.

I had

#define LEAF_CHECK(r)\
  static_assert(::boost::leaf::is_result_type<typename std::decay<decltype(r)>::type>::value, "BOOST_LEAF_CHECK requires a result type");\
  auto &&BOOST_LEAF_TMP = r;\
  if (!BOOST_LEAF_TMP) return BOOST_LEAF_TMP.error()

Thats not safe in a macro, the if is lacking an else.

Makes sense!

Actually, I spoke too soon. My macro-fu is weak. Would you just be worried about someone abusing it like LEAF_CHECK(...); else ...?

The one you proposed would be fine for me, if you think that one's acceptable.

Yes, exactly -- it is a very bad idea to leave an incomplete if statement in a macro. This was the main motivation for adding the scope actually, but it's true that it better without the scope, it would allow you to look at the temp variable during debugging.

I see. Interesting to know the history, and thanks for the fix!