llvm / llvm/llvm-project

[LifetimeSafety] Avoid suggesting lifetimebound on primary templates

Open
#198,632 2 comments 0 reactions 1 assignee Claimed by @NeKon69 View on GitHub
clang:temporal-safety
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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.

```cpp
template
MyObj &spec_func(T &obj); // suggests adding lifetimbound attribute here!
template <>
MyObj &spec_func(MyObj &obj [[clang::lifetimebound]]);
template <>
MyObj &spec_func(MyObj &obj) { return obj; }
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.