Code Monkey home page Code Monkey logo

ppk_assert's People

Contributors

gpakosz avatar onqtam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ppk_assert's Issues

A minor grammar error in the README

"The library is designed to be lightweight would you decide to keep assertions enabled even in release builds (#define PPK_ASSERT_ENABLED 1)"

Unless I don't know something about English language, you need some joining word before "would". Also, the use of "would" is a bit weird here.
It should be something like
"The library is designed to be lightweight so that you can keep assertions enabled even in release builds (#define PPK_ASSERT_ENABLED 1)"

Support both stateful and state-free asserts in one program

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.

Allow custom PPK_ASSERT_DEBUG_BREAK

In the situation where the assert wants to break into the debugger, there is currently some hardcoded choice of using __debugbreak, raise(SIGTRAP), etc. depending on platform.

This is not bad, but it would be nice to let the user #define their own handling for that situation.

For instance, one could use the debugbreak code, which has some more nuanced platform checks, and can use int3 and other methods.

Warning: stringop-truncation on gcc release build

I got this warning when building with gcc for release (not debug, not with clang):

In file included from /usr/include/string.h:494,
                 from /usr/include/c++/10/cstring:42,
                 from ../engine/third-party/PPK_ASSERT/src/ppk_assert.cpp:13:
In function ‘char* strncpy(char*, const char*, size_t)’,
    inlined from ‘ppk::assert::AssertionException& ppk::assert::AssertionException::operator=(const ppk::assert::AssertionException&)’ at ../engine/third-party/PPK_ASSERT/src/ppk_assert.cpp:386:16:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncatio]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../engine/third-party/PPK_ASSERT/src/ppk_assert.cpp: In member function ‘ppk::assert::AssertionException& ppk::assert::AssertionException::operator=(const ppk::assert::AssertionException&)’:
../engine/third-party/PPK_ASSERT/src/ppk_assert.cpp:351:27: note: length computed here
  351 |     size_t length = strlen(message);
      |                     ~~~~~~^~~~~~~~~

Note that I enabled warnings as errors, so this prevents compilation for me, but otherwise it would just be a warning.

I found this thread https://stackoverflow.com/questions/65127257/gcc-strncat-output-may-be-truncated-werror-stringop-truncation-what-does suggesting to use memcpy, but since I don't want to modify third-party code and I want to keep all warnings as errors, I just disabled the stringop-truncation entirely (note it's written as "stringop-truncatio" in the message above).

I personally prefer the more semantical strncpy, so I would understand if you didn't want to use memcpy or use some other tricks to remove the warning. Of course, if you have a clean solution, just go ahead. I looked at the code and the lengths seem correct, but as length is computed dynamically, the compiler may not recognize that.

Even if you don't change your code, I put this issue here so people having the same problem know about some solutions.

[docs] what are PPK_ASSERT_FUNCSPEC and PPK_ASSERT_CALL for?

my guess is - if I want to build ppk_assert as a .dll?

Thanks for the great project!

And a side question - would it be possible to remove as much as possible from the source file if PPK_ASSERT_ENABLED is 0? I don't want to rely on link-time optimizations to remove dead code.

And one more note: Since C++11 local static variables are required to have synchronization added by the compiler for their initialization - so calling the function from multiple threads is safe. This may add A LOT of overhead if asserts are used on hot paths... Maybe this should be mentioned near PPK_ASSERT_DISABLE_IGNORE_LINE in the docs? I will disable this from day 1 in my code...

And one more thing: switching from #include <ppk_assert.h> to #include "ppk_assert.h" would be nice - so the folder doesn't have to be in the include path.

And one more thing : stuff like PPK_ASSERT_ACTION_BREAK from the documentation isn't present in the header - it has been moved to an enum.

Whops - I added quite a few things in this single "issue" :D

compile with gcc 4.8.2

Hi there!

I am trying to use your simple static_assert macro found on this site:
http://pempek.net/articles/2013/11/23/boost-static-assert-without-boost/
It is working with gcc 4.3.4

However I tied with 4.8.2 and got the following:

error: expected \ufffd\ufffd\ufffd)\ufffd\ufffd\ufffd before \ufffd\ufffd\ufffd,\ufffd\ufffd\ufffd token
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: expected unqualified-id before numeric constant
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: \ufffd\ufffd\ufffd__static_assertion_at_line_\ufffd\ufffd\ufffd was not declared in this scope
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: invalid use of incomplete type \ufffd\ufffd\ufffdstruct JOIN\ufffd\ufffd\ufffd
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: forward declaration of \ufffd\ufffd\ufffdstruct JOIN\ufffd\ufffd\ufffd
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: template argument 1 is invalid
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: invalid type in declaration before \ufffd\ufffd\ufffd(\ufffd\ufffd\ufffd token
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");
error: typedef \ufffd\ufffd\ufffdJOIN\ufffd\ufffd\ufffd is initialized (use decltype instead)
error: \ufffd\ufffd\ufffd__static_assertion_test_at_line_\ufffd\ufffd\ufffd was not declared in this scope
 STATIC_ASSERT(false, "no_you_cant_have_a_pony");

Do you have some simple static_assert code which is working on 4.8.2 - any idea what could be the problem?
Thanks in advance!
Balazs

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.