Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check macro that generates a compile-time error if the given expression is not constexpr #75

Open
cschreib opened this issue Mar 18, 2023 · 0 comments
Labels
enhancement New feature or request maybe For issues that aren't critial, or need more exploration

Comments

@cschreib
Copy link
Member

cschreib commented Mar 18, 2023

See #60 (comment).

Use case:

CHECK_IS_CONSTEXPR(constexpr_vector{10}.clear());

Issues:

  • CHECK_IS_CONSTEXPR is confusingly close to CONSTEXPR_CHECK.
  • CHECK_IS_CONSTEXPR vs REQUIRE_IS_CONSTEXPR? It's a compile-time check, so there can't be a difference between the two, yet it would feel imbalanced to have just one. Define both to be the same?

Proposed implementation:

#define SNITCH_CHECK_IS_CONSTEXPR(...)                                                             \
    do {                                                                                           \
        auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test();                              \
        ++SNITCH_CURRENT_TEST.asserts;                                                             \
        SNITCH_WARNING_PUSH                                                                        \
        SNITCH_WARNING_DISABLE_PARENTHESES                                                         \
        SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON                                                 \
        static_assert(((__VA_ARGS__), true));                                                      \
        SNITCH_WARNING_POP                                                                         \
    } while (0)

#define SNITCH_REQUIRE_IS_CONSTEXPR(...)                                                           \
    do {                                                                                           \
        auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test();                              \
        ++SNITCH_CURRENT_TEST.asserts;                                                             \
        SNITCH_WARNING_PUSH                                                                        \
        SNITCH_WARNING_DISABLE_PARENTHESES                                                         \
        SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON                                                 \
        static_assert(((__VA_ARGS__), true));                                                      \
        SNITCH_WARNING_POP                                                                         \
    } while (0)
@cschreib cschreib added enhancement New feature or request maybe For issues that aren't critial, or need more exploration labels Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maybe For issues that aren't critial, or need more exploration
Projects
None yet
Development

No branches or pull requests

1 participant