higher-performance wrote:

> it would be great to get something that "magically" works with a single 
> attribute and does not need complicated compile-time computations. If we 
> cannot get that, the approach with `clang::lifetimebound_like` seems like the 
> second-best alternative.

The closest universal solution I can think of is something like the following, 
assuming we do proper bikeshedding for the name:

```
template<class... Args>
reference emplace_back(Args&&... args)
  [[clang::diagnosis_body(EXPRESSION_REPRESENTING_A_FAKE_BODY)]];
```

The faux body could then be used for diagnosis purposes -- and the contract 
would be that it would never affect codegen.

This would also leave the door open to further extensions in the future. e.g., 
`[[clang::diagnosis_body(..., "lifetime_body_key_1")]] 
[[clang::lifetime_diagnosis_like("lifetime_body_key_1")]]`, to allow different 
analyses to share the same bodies.

> > I think even [[clang::diagnose_if(...)]] can cause template instantiations 
> > that change program behavior.
> 
> Unrelated, but I'd be curious to see those if you have any examples. I 
> thought that maybe SFINAE could cause this, but at least [in simple 
> examples](https://gcc.godbolt.org/z/5EeMhr4nW) `diagnose_if` does not affect 
> overloading.

https://godbolt.org/z/xozfs18Ta (but looks like the 
`[[clang::diagnose_if(...)]]` syntax doesn't actually work for that attribute, 
only `__attribute__` syntax works)

Note that _any_ attribute that can result in template instantiations could 
cause this. (Not sure if that's a necessary condition, but it's sufficient.)

https://github.com/llvm/llvm-project/pull/125520
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to