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

Use function-like macros for prefixless macro names #462

Merged
merged 1 commit into from
Jan 25, 2021

Conversation

tbleher
Copy link
Contributor

@tbleher tbleher commented Jan 25, 2021

The short macros (without "DOCTEST_" prefix) are very useful, but can
collide with existing names.

Example:

  /* LogLevel.h */
  enum class LogLevel {
      FATAL,
      WARN,
      NOTICE,
      INFO,
      DEBUG
  };

This code may break with doctest without
DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES, since doctest defines macros named
"WARN" and "INFO". These macros will then replace the enum enties WARN by
DOCTEST_WARN (and INFO by DOCTEST_INFO). This will break compilation in
the following case:

  #include "LogLevel.h"
  #include "doctest.h"
  static const LogLevel sDefaultLogLevel = LogLevel::INFO;

Fix this by using function-like macros for prefixless macros, so the
preprocessor will only replace the names if followed by braces.

The short macros (without "DOCTEST_" prefix) are very useful, but can
collide with existing names.

Example:

  /* LogLevel.h */
  enum class LogLevel {
      FATAL,
      WARN,
      NOTICE,
      INFO,
      DEBUG
  };

This code may break with doctest without
DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES, since doctest defines macros named
"WARN" and "INFO". These macros will then replace the enum enties WARN by
DOCTEST_WARN (and INFO by DOCTEST_INFO). This will break compilation in
the following case:

  #include "LogLevel.h"
  #include "doctest.h"
  static const LogLevel sDefaultLogLevel = LogLevel::INFO;

Fix this by using function-like macros for prefixless macros, so the
preprocessor will only replace the names if followed by braces.
@tbleher
Copy link
Contributor Author

tbleher commented Jan 25, 2021

@onqtam Two checks fail, but it looks like this is an external error:
E.g. one of the failing tests says:

URL http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-expat-2.2.9-1-any.pkg.tar.xz is not valid

Anything I can do to fix this?

@onqtam
Copy link
Member

onqtam commented Jan 25, 2021

@tbleher This PR seems like a good idea, thanks!

Those CI failures can be ignored - I haven't figured out how to fix them.

@onqtam onqtam merged commit 435eb4a into doctest:dev Jan 25, 2021
@tbleher tbleher deleted the short-function-like-macros branch January 25, 2021 14:45
@tbleher
Copy link
Contributor Author

tbleher commented Jan 25, 2021

@onqtam Wow, that was quick :) Thanks for merging this so fast!

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

Successfully merging this pull request may close these issues.

2 participants