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

syntax error: failed to expand 'HASH_TOKEN_IN_MACRO' #328

Open
chrchr-github opened this issue Oct 23, 2023 · 4 comments
Open

syntax error: failed to expand 'HASH_TOKEN_IN_MACRO' #328

chrchr-github opened this issue Oct 23, 2023 · 4 comments

Comments

@chrchr-github
Copy link
Contributor

chrchr-github commented Oct 23, 2023

From https://trac.cppcheck.net/ticket/12105

void g(const char*);
#define HASH_TOKEN_IN_MACRO( A ) g( #A )
void f() {
	HASH_TOKEN_IN_MACRO (
#ifdef SW
		"Message 1"
#else
		"Message 2"
#endif
	);
}

foo.cpp:5: syntax error: failed to expand 'HASH_TOKEN_IN_MACRO', it is invalid to use a preprocessor directive as macro parameter

@danmar
Copy link
Owner

danmar commented Nov 4, 2023

This code is undefined behavior.

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

page 152

If there are sequences of preprocessing tokens within the list of arguments that would otherwise act as preprocessing directives,150) the behavior is undefined

@danmar danmar closed this as completed Nov 4, 2023
@parrotrueper
Copy link

parrotrueper commented Jan 3, 2024

@danmar Agreed that the code is bad, the linter should flag it and carry on, rather than grind to a halt and stop checking the rest of the code. As a side note this code was created to evaluate linters. Out of five linters Cppcheck was the only one that stopped checking after encountering this error.

@danmar
Copy link
Owner

danmar commented Jan 4, 2024

@parrotrueper I would hope you can consider to fix the evaluation code somehow then. And evaluate cppcheck using that. A user would fix the code and then recheck..

@danmar
Copy link
Owner

danmar commented Jan 4, 2024

alright I guess we can reopen this. Fixing this doesn't mean we have to remove the error message...

@danmar danmar reopened this Jan 4, 2024
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

3 participants