[LifetimeSafety] Avoid suggesting lifetimebound on primary templates
After #197753, we suggest adding lifetimebound to a primary template when the annotation appears on an explicit specialization.
This can be misleading because adding the attribute to the primary template affects all instantiations/specializations, even if only one specialization needs the annotation.
We should either avoid making this suggestion in these cases, or add a more specific diagnostic/suggestion for explicit specializations.
template <typename T>
MyObj &spec_func(T &obj); // suggests adding lifetimbound attribute here!
template <>
MyObj &spec_func<MyObj>(MyObj &obj [[clang::lifetimebound]]);
template <>
MyObj &spec_func<MyObj>(MyObj &obj) { return obj; }
@llvm/issue-subscribers-clang-temporal-safety
Author: NeKon69
This can be misleading because adding the attribute to the primary template affects all instantiations/specializations, even if only one specialization needs the annotation.
We should either avoid making this suggestion in these cases, or add a more specific diagnostic/suggestion for explicit specializations.
template <typename T>
MyObj &spec_func(T &obj); // suggests adding lifetimbound attribute here!
template <>
MyObj &spec_func<MyObj>(MyObj &obj [[clang::lifetimebound]]);
template <>
MyObj &spec_func<MyObj>(MyObj &obj) { return obj; }
I have a fix for this, will create a PR soon.