llvm-project
llvm-project copied to clipboard
clang-cl does not support concatenation of predefined identifiers
According to MSDN __FUNCDNAME__, __FUNCSIG__, and __FUNCTION__ are non-expandible macros defined as string literals. So, they may be concatenated with other string literals (Compiler Explorer link):
extern "C" int printf(const char*, ...);
void F() {
printf("Function name: " __FUNCTION__ "\n");
printf("Decorated function name: " __FUNCDNAME__ "\n");
printf("Function signature: " __FUNCSIG__ "\n");
}
Currently clang in ms-compatible mode does not support this.
Relevant issue: #12161
I've tried to tackle this problem in two approaches:
- Make expansion of predefined literals directly in
StringLiteralParser, however I stumbled upon a fact that I need access to AST in Lex (which is unreasonable to link them together; namely I needed access toPredefinedExpr::ComputeName). - Replace tokens of predefined literals in in
Sema::ActOnStringLiteralwith string-literal tokens (from scratch buffer).
Yes, (2) feels hacky, but I couldn't came up with any other approach, and unfortunately, it seems that support of this MSFT extension doesn't fit well into the current architecture of clang. Anyways, I've submitted my patch for review; feel free to reject it.