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

Support both stateful and state-free asserts in one program #11

Open
jwdevel opened this issue Jan 31, 2020 · 2 comments
Open

Support both stateful and state-free asserts in one program #11

jwdevel opened this issue Jan 31, 2020 · 2 comments

Comments

@jwdevel
Copy link

jwdevel commented Jan 31, 2020

Currently, one must decide at compile time whether PPK_ASSERT will use a static bool _ignore flag or not (see: PPK_ASSERT_DISABLE_IGNORE_LINE).

However, I have a program that largely should use that bool, but can't in certain places.
The place where it is not allowed is inside a constexpr function.

eg:

constexpr int myFunc(int arg) {
    PPK_ASSERT(arg != 0);
    /* ... */
    return arg+5;
}

This fails to compile for me, with:

ppk_assert.h line 243 col 23: error: ‘_ignore’ declared ‘static’ in ‘constexpr’ function

So, it would be nice if there were some PPK_ASSERT_NOSTATE(...) set of macros that could be used in this case, even if the normal PPK_ASSERT(...) macros do keep state.

@gpakosz
Copy link
Owner

gpakosz commented Jan 31, 2020

Hello @jwdevel 👋

I don't understand how this would fly 🤔

Even though you manage to use PPK_ASSERT in a constexpr function, I don't get how this composes with the fact that the handling part is designed to happen at runtime 🤷‍♂️

@jwdevel
Copy link
Author

jwdevel commented Jan 31, 2020

Hi @gpakosz,

Yes, I take your point, and maybe PPK_ASSERT is just a runtime-only facility.

I went down this path because I can use plain assert() in my constexpr functions. Having done some research, this is a C++14-specific thing. Even though it is constexpr, it will fail at runtime when the condition is met (at least, I just tried this on GCC 8.3).

So, maybe this request is a bit outside the scope of PPK_ASSERT.
I just thought it would be nice to take advantage of all the other machinery that PPK_ASSERT provides, handling various arguments, etc. But if it all boiled down to plain assert it could be used in a constexpr function on C++14.

In researching this, I found some interesting info, eg SO question, blog post.

So I guess feel free to close this if you like (:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants