[clang] Add isTrivial() and isTriviallyCopyable() AST matchers (PR #90634)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 18:07:47 PDT 2024


higher-performance wrote:

@AaronBallman: Oh I see. I didn't have any plans to upstream any matchers that used this, though I suppose I could. The check I had in mind though ostensibly could be in-tree, if you guys were interested. Though now that I think about it more, I think it would need `isTriviallyDestructible` rather than `isTrivially`. It basically detects whether there is an assignment of the form
```
<trivialy_destructible_type> = <destructible_type>;
```
which is frequently (but not always) dubious.
The canonical example here would be:
```
std::string Get();
std::string_view sv;
sv = Get();  // dangling pointer
```
which results in a dangling pointer. `-Wdangling` would catch the obvious candidates annotated with `lifetimebound`, but this check would surface things that might not be annotated.

https://github.com/llvm/llvm-project/pull/90634


More information about the cfe-commits mailing list