You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the # operator turns a macro argument into a string, simplecpp puts a \ before every \, " and ' in the argument. The standard says a \ is inserted only before each " and \ that is part of a string literal or
character constant (C11 §6.10.3.2p2, C++ [cpp.stringize]). Other backslashes are copied unchanged, and ' is never escaped.
Example
#definestr(x) #x
str(\n)
str(: @\n)
str('\4')
Input
Expected (gcc, clang)
Actual (simplecpp)
str(\n)
"\n"
"\\n"
str(: @\n)
": @\n"
": @\\n"
str('\4')
"'\\4'"
"\'\\4\'"
str(: @\n) is taken from the standard's own example (C11 §6.10.3.5, example 4). The clang testsuite case c99-6_10_3_4_p6.c fails for the same reason.
Activity
Fix #714 (# operator escapes backslashes outside string literals)
Fix cppcheck-opensource#714 (# operator escapes backslashes outside s…