[PATCH] D136343: [Lex] Add compatibility with MSVC

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 21 05:46:14 PDT 2022


aaron.ballman added a comment.

In D136343#3873284 <https://reviews.llvm.org/D136343#3873284>, @Qfrost911 wrote:

> I understand you mean, but I can't get function name at macro expedition stage.

Correct! We have a `PredefinedExpr` AST node type (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/Expr.h#L1968) to handle this, and it seems we already support `__FUNCTION__` (and friends): https://godbolt.org/z/cEWh1Prnx. However, we're matching the GCC behavior for printing a member function name instead of following the MSVC behavior when in `-fms-compatibility` mode, which we might want to consider changing.

The reason your code example in the summary doesn't compile is because a `PredefinedExpr` is not a string literal, so there is no way to do string concatenation with an adjacent literal. MSVC implements these as actual macros that expand to a string literal, which is not a behavior Clang can easily match.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136343/new/

https://reviews.llvm.org/D136343



More information about the cfe-commits mailing list