Skip to content

Defect: Prepocessor fails to expand x-macro macro parameter #201

Description

@mavik1

cppcheck fails to preprocess the code below:

> cppcheck --version
Cppcheck 2.3
> cppcheck -E main.c
main.c:12:0: error: failed to expand 'COLOR_SET', Wrong number of parameters for macro 'ALL_COLORS'. [preprocessorErrorDirective]
#define COLOR_SET ALL_COLORS(WARM_COLORS)
^

main.c:

#define ALL_COLORS(warm_colors) \
	X(Blue) \
	X(Green) \
	X(Purple) \
	warm_colors

#define WARM_COLORS \
	X(Red) \
	X(Yellow) \
	X(Orange)

#define COLOR_SET ALL_COLORS(WARM_COLORS)

#define X(color) #color,

COLOR_SET

gcc handles it fine:

> gcc -E main.c
# 1 "main.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "main.c"
# 16 "main.c"
"Blue", "Green", "Purple", "Red", "Yellow", "Orange",

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions