================
@@ -35,6 +35,13 @@ AST_MATCHER_P(Stmt, nextStmt,
ast_matchers::internal::Matcher<Stmt>,
return InnerMatcher.matches(**I, Finder, Builder);
}
+
+AST_MATCHER(Expr, isUnsupportedRangeInit) {
+ const Expr *E = Node.IgnoreParenImpCasts();
+ if (Finder->getASTContext().getLangOpts().CPlusPlus20)
+ return isa<CXXStdInitializerListExpr>(E);
----------------
5chmidti wrote:
I would've expected:
```C++
const Expr *E = Node.IgnoreParenImpCasts();
if (Finder->getASTContext().getLangOpts().CPlusPlus20)
// the ranges versions will handle temporaries correctly
return false;
return E->isPRValue();
```
And the temporary initializer list may have been written with the type
explicitlly: https://godbolt.org/z/b1KeGKc19
But taking one step back: Is this an actual 'issue'? (besides the potentially
wrong fix implementation by the user?)
>From the issue:
```c++
#include <initializer_list>
bool f(int a, int b, int c) {
for (const auto i : { a, b, c }) {
if (i == 0)
return true;
}
return false;
}
bool g(int a, int b, int c) {
auto range = { a, b, c };
return std::any_of(range.begin(), range.end(), [](const auto val){ return
val == 0; });
}
```
Maybe what should happen instead is if the init is a temporary, the message is
slightly different hinting at the lifetime, or do the same with a note?
CC @chrchr-github
https://github.com/llvm/llvm-project/pull/185791
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits