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

-fms-compatibility: Clang should form a wide string literal from L#macro_arg in a function-like macro #10356

Closed
llvmbot opened this issue May 22, 2011 · 4 comments
Labels
bugzilla Issues migrated from bugzilla c++

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented May 22, 2011

Bugzilla Link 9984
Resolution FIXED
Resolved on Dec 14, 2014 22:19
Version trunk
OS All
Blocks llvm/llvm-bugzilla-archive#13707
Reporter LLVM Bugzilla Contributor
CC @alexey-bataev,@majnemer,@DougGregor,@zmodem,@zygoloid,@rnk

Extended Description

the following code produces an error:

#define TESTL(x) L#x
const wchar_t* a = L"Hello World";
const wchar_t* b = TESTL(Hello World);

The preprocessor appears to ignore the L inside the define as the literal declaring the string as a wide string. The code not using the macro passes without error.

Here is the analyzer output:

"Use of undeclared identifier 'L'"

This fails on both using the analyzer that ships with XCode 4.0.1 as well as svn trunk (test at revision 131851).

@DougGregor
Copy link
Contributor

Clang is behaving correctly here (as does GCC). You can't both stringize a token and concatenate in one step. Instead, use:

#define TESTL2(x) L##x
#define TESTL(x) TESTL2(#x)
const wchar_t* a = L"Hello World";
const wchar_t* b = TESTL(Hello World);

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 22, 2011

Clang is behaving correctly here (as does GCC). You can't both stringize a
token and concatenate in one step. Instead, use:

#define TESTL2(x) L##x
#define TESTL(x) TESTL2(#x)
const wchar_t* a = L"Hello World";
const wchar_t* b = TESTL(Hello World);

It also works with:

#define TESTL(x) L###x
const wchar_t* a = L"Hello World";
const wchar_t* b = TESTL(Hello World);

I wasn't sure of the desired behaviour of "L#x" in clang (or that GCC doesn't allow for it either), I ran into it while trying to analyze some Microsoft example code while working on a Visual Studio plugin for the clang analyzer. Is this something that should be added to the clang Microsoft extensions?

@rnk
Copy link
Collaborator

rnk commented Jun 17, 2014

IMO we should consider lexing this as a single wide string literal in -fms-compatibility mode. There appear to be lots of Windows applications using this idiom to form wide string literals from macro arguments.

@alexey-bataev
Copy link
Member

Fixed in revision 224228

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++
Projects
None yet
Development

No branches or pull requests

4 participants