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

Print Predicate for Compile-time Assertions on Failure #273

Closed
jwillikers opened this issue Dec 31, 2019 · 5 comments
Closed

Print Predicate for Compile-time Assertions on Failure #273

jwillikers opened this issue Dec 31, 2019 · 5 comments

Comments

@jwillikers
Copy link
Contributor

Is it possible to have the predicate printed for constant expressions when there is a failure?

Take the following code as an example, which is taken from the tutorial but evaluated at compile-time.

int main() {
  using namespace boost::ut;
  expect(constant<1_i == 2>);
}

Is it possible to get output similar to the following at run-time where the predicate is shown on failure?

main.cpp:4:FAILED [1 == 2]
===============================================================================
tests:   0 | 0 failed
asserts: 1 | 0 passed | 1 failed

@kris-jusiak
Copy link
Contributor

Not sure whether I fully understand, isn't the following what you are asking for 🤔

expect(1_i == 2);

@jwillikers
Copy link
Contributor Author

If I understand correctly, constant is for evaluating an expression at compile time. Please correct me if I'm wrong. When using constant the output for a failure is either true or false instead of a more detailed message containing the assertion. This is most likely a rather niche concern and possible a terrible idea anyways, but if you want to let users do more at compile time it might make sense. Maybe. 😶

@kris-jusiak
Copy link
Contributor

Ah, I see, yeah, you are right, constant is to ensure that expression can be evaluated at compile-time. It actually shows the expression (instead of true/false) if NTTP is supported (only gcc ATM, though, clang doesn't have it yet 😞).

NTTP branch -> https://github.com/boost-experimental/ut/blob/master/include/boost/ut.hpp#L1880
Full example -> https://godbolt.org/z/GJqhsE (it shows the expression in gcc but in clang it only shows true/false)

For the time being, for clang, I'd stick with the run-time version to see the expression and check whether it's constant on top of that (that works for both: clang and gcc)

constexpr auto expr = 1_i == 2;
expect(expr and constant<expr>);

Full example here -> https://godbolt.org/z/Zd-Ni9

@jwillikers
Copy link
Contributor Author

Awesome! That's exactly what I was talking about. 😌

@kris-jusiak
Copy link
Contributor

👍

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