================
@@ -922,6 +928,24 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
if (const MacroDefinition MD = getMacroDefinition(&II)) {
const auto *MI = MD.getMacroInfo();
assert(MI && "macro definition with no macro info?");
+ // C++ [cpp.pre]/p4, [cpp.cond]/p9: if one of the pp-tokens of a #embed
+ // directive (or a has-embed-expression) is the identifier limit, prefix,
+ // suffix, or if_empty and that identifier is defined as a macro, the
+ // program is ill-formed.
+ //
+ // Thus, do not continue processing if compiling for C++. C doesn't have
+ // this restriction however, so only issue a warning for C if -Wc++-compat
+ // is enabled.
----------------
ianayl wrote:
I couldn't find any rules preventing the macro expansion from happening in the
C standard, but I'm going off of admittedly a pretty inexperienced
interpretation of these standards. However,
[N3912](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3912.htm#intro) (for
synchronizing C/C++ behavior of `#embed`) makes the assertion that we _should_
expand macros in C in the future:
> Preprocessor expansion of parameters always happens, not just for limit, and
> it is performed for everything after the resource name instead of just for
> inside of the parameters (a previous design in the C++ proposal, revision 13).
So... maybe I was wrong, and instead this is future proposed behavior? If this
behavior is intentional in the future, is it worth gating it for anything below
C2y? It's worth noting N3912 also makes an acknowledgement of CWG3013 despite
having no rule similar to CWG3013.
Also worth noting that currently, both clang and gcc expands all macros after
the resource file regardless: https://godbolt.org/z/YcP5efKdn
Do you have any opinions/recommendations on this?
***
@ThePhD Please excuse the ping, but could I ask for clarification w.r.t what
the behavior of
```c
#define prefix suffix
const char a[] = {
#embed __FILE__ prefix(0)
};
```
should be in C23 now vs C2y? And regarding whether or not there are drafts for
C2y that plans on implementing behavior similar to CWG3013? Thanks a ton in
advance!
https://github.com/llvm/llvm-project/pull/224769
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits