hans added a comment.
Interesting, I hadn't seen __identifier before. It seems like a pretty esoteric
feature.
================
Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1817
+ else if (Tok.is(tok::string_literal)) {
+ const StringRef StrData(Tok.getLiteralData() + 1, Tok.getLength() - 2);
+ Tok.setIdentifierInfo(this->getIdentifierInfo(StrData));
----------------
I'm not sure this is the right way to get the string out of a string_literal..
this pattern seems more common:
https://github.com/llvm/llvm-project/blob/llvmorg-12.0.0/clang/lib/Lex/Pragma.cpp#L755
For example, what should happen with __identifier("foo" "bar")?
================
Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1819
+ Tok.setIdentifierInfo(this->getIdentifierInfo(StrData));
+ Tok.setKind(tok::identifier);
+ } else {
----------------
It says in the bug report that MSVC emits a warning for this. What does the
warning look like, and would it make sense for Clang too warn too (it might
not, just wondering if we should consider it).
================
Comment at: clang/test/Parser/MicrosoftExtensions.cpp:273
__identifier(+) // expected-error {{cannot convert '+' token to an
identifier}}
- __identifier("foo") // expected-error {{cannot convert <string_literal>
token to an identifier}}
__identifier(;) // expected-error {{cannot convert ';' token to an
identifier}}
----------------
Maybe instead of removing this, move it to the cases that work above. For
example, I guess this should work now?
```
int __identifier("foo") = 42;
int bar = foo;
```
================
Comment at: clang/test/Parser/MicrosoftExtensions.cpp:276
+ __identifier("+"); // expected-error {{use of undeclared identifier '+'}}
+ __identifier(";"); // expected-error {{use of undeclared identifier ';'}}
}
----------------
It would be interesting to see a non-error test case too, perhaps with a
mangled name like in the PR, and to see that it makes it through to LLVM IR
correctly..
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100252/new/
https://reviews.llvm.org/D100252
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits