================
@@ -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);
----------------
zeyi2 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();
> ```

IMHO return `false` directly may be too broad, please see the comment above.

> 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?

Thanks for the suggestion!

A quick draft: `note: reusing the temporary range directly in the replacement 
may be unsafe; consider materializing it in a local variable first`? 

That said, I'm a bit unsure whether this should be done in this PR or as a 
follow-up, as this PR is intended as a narrow fix for the current 
false-positive. Changing the diagnostic wording/notes would expand the scope 
into a design question for the check. IMO this is better tracked separately.

If you think this should be part of this PR, I can update the patch 
accordingly. WDYT?


https://github.com/llvm/llvm-project/pull/185791
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to