Skip to content

BOOST_PP_REMOVE_PARENS() is dangerously broken -- it strips initial group of parentheses instead of surrounding #65

@higher-performance

Description

@higher-performance

https://godbolt.org/z/38jbTP7qn

#include <boost/preprocessor/punctuation/remove_parens.hpp>

int main(int argc, char *argv[]) {
#if MACRO
  return BOOST_PP_REMOVE_PARENS((*argv)[1]);  // Crash
#else
  return                        (*argv)[1] ;  // OK
#endif
}

Note the documentation piles extra confusion on top of this. It says:

The BOOST_PP_REMOVE_PARENS macro removes the beginning parenthesis, if it exists, from the input data and expands to the result

"Parenthesis" is singular (plural is parentheses), so the documentation is claiming that only a beginning ( is being removed. It makes no mention of removing any closing ), regardless of its expected location, even though the function apparently does that regardless of its location.

This is a massive pitfall. The name BOOST_PP_REMOVE_PARENS itself (and the intended usage) are misleading for most users and very unlikely to be what they actually want.

I would suggest, at the very least, renaming the macro to something like BOOST_PP_REMOVE_BEGINNING_PARENS and updating the documentation to clarify it is not doing what users would expect from a REMOVE_PARENS macro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions