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

ROS_ASSERT_CMD missing parentheses around condition #271

Closed
b-adkins opened this issue Aug 7, 2013 · 0 comments
Closed

ROS_ASSERT_CMD missing parentheses around condition #271

b-adkins opened this issue Aug 7, 2013 · 0 comments
Assignees

Comments

@b-adkins
Copy link

b-adkins commented Aug 7, 2013

This...

#define ROS_ASSERT_CMD(cond, cmd) \
  do { \
    if (!cond) { /* This line */ \
      cmd; \
    } \
  } while (0)

...should be...

#define ROS_ASSERT_CMD(cond, cmd) \
  do { \
    if (!(cond)) {  /* This line */ \
      cmd; \
    } \
  } while (0)

...like it is in ROS_ASSERT() and ROS_ASSERT_MSG(), so that developers don't have to wrap the cond argument in parentheses themselves.

To reproduce, try to compile a ROS_ASSERT_CMD statement where the !cond would be invalid.

E.g. with the following code...

ROS_ASSERT_CMD(myObject == myObject2, return false);

...the compiler will complain that it can't apply the '!' operator to myObject.

So the developer has to use:

ROS_ASSERT_CMD((myObject == myObject2), return false);

But for the other ASSERT macros he/she can keep the natural form:

ROS_ASSERT(myObject == myObject2);
ROS_ASSERT_MSG(myObject == myObject2, "Objects aren't equal!");
@ghost ghost assigned dirk-thomas Aug 7, 2013
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