Code Monkey home page Code Monkey logo

Comments (4)

onqtam avatar onqtam commented on May 20, 2024

This is planned to be fixed (the way Catch does it) in 1.1 - I will also limit the expression decomposition to only binary expressions the same way.

Unfortunately the release of 1.1 was delayed but it will come. Thanks for the report!

I think that in this particular case 9 || 1 gets evaluated first and the result is a bool, and then that bool is compared to 1 which results in a bool which is compared to 8 which gets converted to a bool true and so the test "passes". Adding parenthesis should fix this - like this: (1==9) || (1==8)

from doctest.

raulh39 avatar raulh39 commented on May 20, 2024

That's great news!

This is happening because of the way ExpressionDecomposer() works, right?

I do not think that 9 || 1 gets evaluated first. It seems to me that doctest is expanding

CHECK(1==9 || 1==8);

as

ExpressionDecomposer() << 1==9 || 1==8;

Taking operator precedence, operator << it's the first to evaluate, producing an instance of Expression_lhs.
Then the first == is evaluated, and an instance of Result is generated. Call it "r".
So in the end, this is what the compiler sees:

r || 1==8;

As Result has a bool conversion operator that, in this case, gets evaluated to true, the whole expression is evaluated to true.

I see that this line

//template <typename R> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator||(const R&);

is commented out in the Result class. I imagine that in version 1.1 you are going to take out the comment and then the same result that in Catch will be obtained.

Ok, thank you for your great library.

from doctest.

onqtam avatar onqtam commented on May 20, 2024

actually you are right :D

from doctest.

onqtam avatar onqtam commented on May 20, 2024

I forgot this issue and I logged another one for the same thing. It should be done in the dev branch - only the reasonable expressions will be allowed and for anything else a static assert with a message will be used. Version 1.1 incoming in the next few days!

from doctest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.