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
int main()
{
wchar_t const* message = L"Hello, my version is " STRINGIZE(HELLO_VERSION) L"\n";
fwprintf(stdout, message);
}
C:\Users\billy_000\Desktop>cl /EHsc /W4 /nologo example.cpp && example.exe
example.cpp
Hello, my version is 1.0.0
C:\Users\billy_000\Desktop>clang++ -o example_clang.exe example.cpp
example.cpp:9:54: error: expected ';' at end of declaration
wchar_t const* message = L"Hello, my version is " STRINGIZE(HELLO_VERSION) L"\n";
^
;
1 error generated.
C:\Users\billy_000\Desktop>clang++ -o example_clang.exe example.cpp
example.cpp:9:31: error: expected ';' at end of declaration
L"Hello, my version is " STRINGIZE(HELLO_VERSION)L"\n";
^
;
1 error generated.
Thanks!
The text was updated successfully, but these errors were encountered:
#define STRINGIZE_LITERAL(x) L#x
#define STRINGIZE(x) STRINGIZE_LITERAL(x)
[...]
Unfortunately I don't know anything about the preprocessor, so I don't know
if this STRINGIZE macro is just bogus.
It is. With a correct preprocessor, this will always produce two separate tokens: an 'L' token and a string literal.
Extended Description
This bug is similar to bug 17122 ( http://llvm.org/bugs/show_bug.cgi?id=17122 ), except the bug happens in the macro, not in the use of the macro.
Input:
#define STRINGIZE_LITERAL(x) L#x
#define STRINGIZE(x) STRINGIZE_LITERAL(x)
Output:
#define STRINGIZE_LITERAL(x) L #x
#define STRINGIZE(x) STRINGIZE_LITERAL(x)
(Note the space inserted after the L)
Unfortunately I don't know anything about the preprocessor, so I don't know if this STRINGIZE macro is just bogus.
Example:
C:\Users\billy_000\Desktop>type example.cpp
#include
#define HELLO_VERSION 1.0.0
#define STRINGIZE_LITERAL(x) L#x
#define STRINGIZE(x) STRINGIZE_LITERAL(x)
int main()
{
wchar_t const* message = L"Hello, my version is " STRINGIZE(HELLO_VERSION) L"\n";
fwprintf(stdout, message);
}
C:\Users\billy_000\Desktop>cl /EHsc /W4 /nologo example.cpp && example.exe
example.cpp
Hello, my version is 1.0.0
C:\Users\billy_000\Desktop>clang++ -o example_clang.exe example.cpp
example.cpp:9:54: error: expected ';' at end of declaration
wchar_t const* message = L"Hello, my version is " STRINGIZE(HELLO_VERSION) L"\n";
^
;
1 error generated.
C:\Users\billy_000\Desktop>clang-format -style=LLVM -i example.cpp
C:\Users\billy_000\Desktop>type example.cpp
#include
#define HELLO_VERSION 1.0.0
#define STRINGIZE_LITERAL(x) L #x
#define STRINGIZE(x) STRINGIZE_LITERAL(x)
int main() {
wchar_t const *message =
L"Hello, my version is " STRINGIZE(HELLO_VERSION)L"\n";
fwprintf(stdout, message);
}
C:\Users\billy_000\Desktop>cl /EHsc /W4 /nologo example.cpp && example.exe
example.cpp
example.cpp(9) : error C2146: syntax error : missing ';' before identifier 'L'
example.cpp(9) : error C2065: 'L' : undeclared identifier
example.cpp(9) : error C2143: syntax error : missing ';' before 'string'
example.cpp(9) : error C2308: concatenating mismatched strings
Concatenating narrow "1.0.0" with wide "
"
C:\Users\billy_000\Desktop>clang++ -o example_clang.exe example.cpp
example.cpp:9:31: error: expected ';' at end of declaration
L"Hello, my version is " STRINGIZE(HELLO_VERSION)L"\n";
^
;
1 error generated.
Thanks!
The text was updated successfully, but these errors were encountered: