Skip to content

clang-tidy check failure on clang-analyzer-optin.core.EnumCastOutOfRange #311

@LinZhihao-723

Description

@LinZhihao-723

I got the following clang-tidy errors:

home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:3369:22: error: The value '34' provided to the cast expression is not in the valid range of values for 'status' [clang-analyzer-optin.core.EnumCastOutOfRange,-warnings-as-errors]
 3369 |       status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
      |                      ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:3271:14: note: enum declared here
 3271 |   enum class status : uint16_t
      |   ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
 3272 |   {
      |   ~
 3273 |     // WARNING: These bits are not tracked by abi-dumper, but changing them will break ABI!
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3274 |     none = 0,
      |     ~~~~~~~~~
 3275 |     have_value = (1U << 0U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
 3276 |     have_error = (1U << 1U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~
 3277 |     have_exception = (2U << 1U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3278 |     have_error_exception = (3U << 1U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3279 |     // failed to complete a strong swap
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3280 |     have_lost_consistency = (1U << 3U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3281 |     have_value_lost_consistency = (1U << 0U) | (1U << 3U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3282 |     have_error_lost_consistency = (1U << 1U) | (1U << 3U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3283 |     have_exception_lost_consistency = (2U << 1U) | (1U << 3U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3284 |     have_error_exception_lost_consistency = (3U << 1U) | (1U << 3U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3285 |     // can errno be set from this error?
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3286 |     have_error_is_errno = (1U << 4U),
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/components/core/src/clp/ffi/ir_stream/search/QueryHandlerImpl.cpp:298:13: note: Taking false branch
  298 |     query = OUTCOME_TRYX(preprocess_query(query));
      |             ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8366:27: note: expanded from macro 'OUTCOME_TRYX'
 8366 | #define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
      |                           ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8362:48: note: expanded from macro 'OUTCOME_TRYX2'
 8362 | #define OUTCOME_TRYX2(unique, retstmt, ...) ({ OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); })
      |                                                ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8322:123: note: expanded from macro 'OUTCOME_TRYV2_SUCCESS_LIKELY'
 8322 | #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
      |                                                                                                                           ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8301:36: note: expanded from macro 'OUTCOME_TRY_LIKELY_IF'
 8301 | #define OUTCOME_TRY_LIKELY_IF(...) if(__VA_ARGS__) [[likely]]
      |                                    ^
/home/lzh/clp/components/core/src/clp/ffi/ir_stream/search/QueryHandlerImpl.cpp:298:13: note: Calling 'try_operation_return_as<outcome_v2::basic_result<std::shared_ptr<clp_s::search::ast::Expression>, std::error_code, outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr<clp_s::search::ast::Expression>, std::error_code, void>>>'
  298 |     query = OUTCOME_TRYX(preprocess_query(query));
      |             ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8366:27: note: expanded from macro 'OUTCOME_TRYX'
 8366 | #define OUTCOME_TRYX(...) OUTCOME_TRYX2(OUTCOME_TRY_UNIQUE_NAME, return, __VA_ARGS__)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8362:48: note: expanded from macro 'OUTCOME_TRYX2'
 8362 | #define OUTCOME_TRYX2(unique, retstmt, ...) ({ OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, deduce, __VA_ARGS__); ::OUTCOME_V2_NAMESPACE::try_operation_extract_value(static_cast<decltype(unique) &&>(unique)); })
      |                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8322:284: note: expanded from macro 'OUTCOME_TRYV2_SUCCESS_LIKELY'
 8322 | #define OUTCOME_TRYV2_SUCCESS_LIKELY(unique, retstmt, spec, ...) OUTCOME_TRYV2_UNIQUE_STORAGE(unique, spec, __VA_ARGS__); OUTCOME_TRY_LIKELY_IF(::OUTCOME_V2_NAMESPACE::try_operation_has_value(unique)); else { /* works around ICE in GCC's coroutines implementation */ auto unique##_f(::OUTCOME_V2_NAMESPACE::try_operation_return_as(static_cast<decltype(unique) &&>(unique))); retstmt unique##_f; }
      |                                                                                                                                                                                                                                                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:8237:10: note: Calling 'basic_result::as_failure'
 8237 |   return static_cast<T &&>(v).as_failure();
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:5770:5: note: Calling 'status_bitfield_type::set_have_moved_from'
 5770 |     this->_state._status.set_have_moved_from(true);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:3369:42: note: 'v' is true
 3369 |       status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
      |                                          ^
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:3369:42: note: '?' condition is true
/home/lzh/clp/build/deps/core/outcome-install/include/outcome/outcome.hpp:3369:22: note: The value '34' provided to the cast expression is not in the valid range of values for 'status'
 3369 |       status_value = static_cast<status>(v ? (static_cast<uint16_t>(status_value) | static_cast<uint16_t>(status::have_moved_from)) :
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 3370 |                                              (static_cast<uint16_t>(status_value) & ~static_cast<uint16_t>(status::have_moved_from)));
      |                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My source code that triggers the issue: https://github.com/LinZhihao-723/clp/blob/350552c270933be411448dc88c0e2c18c4661fab/components/core/src/clp/ffi/ir_stream/search/QueryHandlerImpl.cpp#L298
The version of outcome I used: v2.2.9
Is this sth expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions