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

Definition of UNDEBUG info in RelWithDebInfo breaks principle of least astonishment? #417

Closed
traversaro opened this issue Mar 23, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@traversaro
Copy link
Contributor

(sorry for ignoring the template, but this discussion did not fit really the template)

I recently discovered (see conda-forge/gz-physics-feedstock#26 (comment)) that gz-cmake defined UNDEBUG (i.e. undefined -DNDEBUG) for RelWithDebInfo.

The motivation for this reported in the code (see

# -UNDEBUG: Undefine the NDEBUG symbol so that assertions get triggered in
# RelWithDebInfo mode
# NOTE: Always make -UNDEBUG the first flag in this list so that it appears
# immiediately after cmake's automatically provided -DNDEBUG flag.
# Keeping them next to each other should make it more clear that the
# -DNDEBUG flag is being canceled out.
) are the following:

  # -UNDEBUG: Undefine the NDEBUG symbol so that assertions get triggered in
  #           RelWithDebInfo mode
  # NOTE: Always make -UNDEBUG the first flag in this list so that it appears
  #       immiediately after cmake's automatically provided -DNDEBUG flag.
  #       Keeping them next to each other should make it more clear that the
  #       -DNDEBUG flag is being canceled out.

However, this seems to be quite error prone. RelWithDebInfo has a specific meaning with which CMake users are familiar with, that is basically "Release builds with debug symbols enabled" (that is not entirely true, as Release use -O3 while RelWithDebInfo -O2, but that is another story. The expectation of most users is that in RelWithDebInfo builds, NDEBUG is defined, and so no assert are enabled.

To make you an example, when compiling in RelWithDebInfo users do not expect particular slowdown w.r.t. to Release, and sometimes NDEBUG is used also to disable expensive checks (see for example for Eigen http://eigen.tuxfamily.org/index.php?title=FAQ#How_do_I_get_good_performance.3F).

Perhaps we can look into removing the -DUNDEBUG definition in gz-cmake4?

@traversaro traversaro added the bug Something isn't working label Mar 23, 2024
@mjcarroll
Copy link
Contributor

I agree that even as someone who has spent time in this codebase, this is surprising. I'm okay with going back to the standard set of flags here.

@j-rivero
Copy link
Contributor

Perhaps we can look into removing the -DUNDEBUG definition in gz-cmake4?

Totally in favor in the change yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants