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

cppcoreguidelines-macro-usage warns about comma wrapper macro #39945

Closed
pavelkryukov opened this issue Feb 5, 2019 · 5 comments
Closed

cppcoreguidelines-macro-usage warns about comma wrapper macro #39945

pavelkryukov opened this issue Feb 5, 2019 · 5 comments
Labels
bugzilla Issues migrated from bugzilla clang-tidy

Comments

@pavelkryukov
Copy link

Bugzilla Link 40599
Version unspecified
OS All
CC @JonasToth,@EugeneZelenko,@joto,@LegalizeAdulthood,@Trass3r

Extended Description

Hi

cppcoreguidelines-macro-usage warning checks warns about
a commonly used wrapper around comma. It is used for other
preprocessing stuff (e.g. to call with a single # afterwards),
and there is no chance to convert it to any function.

file.h:1:9: warning: macro 'COMMA' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
#define COMMA ,

@joto
Copy link
Mannequin

joto mannequin commented Aug 9, 2019

Similar cases:

#define NORETURN [[noreturn]]

or

#define DEPRECATED attribute((deprecated))

They also can't be expressed "using a 'constexpr' constant"

@Trass3r
Copy link
Contributor

Trass3r commented Oct 9, 2019

Or the very common dll export pattern:

#if LIB_EXPORTS
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT __declspec(dllimport)
#endif

@LegalizeAdulthood
Copy link
Contributor

In all these cases the contents of the macro are not anything that could be considered a constant.

#define COMMA ,

The replacement text is a token, not a constant.

#define NORETURN [[noreturn]]

The replacement text is three tokens.

etc.

The check will probably need to consider not only the macro definition, but also the contexts in which the macro is expanded. Yeah, this is a giant PITA, but that's what macros are... a PITA.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@LegalizeAdulthood
Copy link
Contributor

[clang-tidy] Narrow cppguidelines-macro-usage to actual constants
https://reviews.llvm.org/D116386

@pavelkryukov
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang-tidy
Projects
None yet
Development

No branches or pull requests

3 participants