[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 25 11:16:06 PDT 2023
rsmith added a comment.
Sorry for the late comments.
================
Comment at: clang/lib/Sema/SemaInit.cpp:167-177
} else if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
E = PE->getSubExpr();
} else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
assert(UO->getOpcode() == UO_Extension);
E = UO->getSubExpr();
} else if (GenericSelectionExpr *GSE = dyn_cast<GenericSelectionExpr>(E)) {
E = GSE->getResultExpr();
----------------
The duplication between this and `IgnoreParensSingleStep` is a code smell; can we expose `IgnoreParensSingleStep` and call it from here?
================
Comment at: clang/lib/Sema/SemaInit.cpp:8511
+ Expr *Init = Args[0];
+ S.Diag(Init->getBeginLoc(), diag::ext_init_from_predefined) << Init;
+ }
----------------
We won't reach this case for `const char arr[] = {__func__};` because in that case `Args[0]` will be an `InitListExpr` instead. Right now we accept this with no warning in MS extensions mode:
```
void f() {
const char c[] = {__func__};
}
```
We should perform this check in the handling of `SK_StringInit` instead, in order to properly address that case.
Also, this will only catch the case where the argument is an unparenthesized predefined expression. You'll need to do something like repeatedly calling `IgnoreParensSingleStep` looking for a `PredefinedExpr` to cope with things like:
```
void g() {
const char c[] = (__func__);
const char d[] = _Generic(0, int: __func__);
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146764/new/
https://reviews.llvm.org/D146764
More information about the cfe-commits
mailing list