<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/68456>68456</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Support `warn_unused_result` on alias templates?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
snarkmaster
</td>
</tr>
</table>
<pre>
Like @dwblaikie in https://reviews.llvm.org/D102122, I am looking to annotate a very common error return type in my codebase as "[[nodiscard]]" to make it less likely that error handling gets forgotten.
However, I'm talking about a new-ish C++ codebase (actually several!), so we use templated types, analogous to this:
```
template <typename T>
using SystemMaybe = std::expected<T, std::system_error>;
```
While it's morally very similar, I can't use David's fancy new attribute here, because it's not supported syntactically -- I tried all the permutations, e.g. https://godbolt.org/z/EP34Tac7s
This leaves me with only not-great options:
- Try to mark every function `[[nodiscard]] SystemMaybe<>` -- noisy and prone to being forgotten (clang-tidy to the rescue).
- Define my own `expected` type with `[[nodiscard]]` composing the standard one -- very expensive in terms of the amount of boilerplate I need. Not going to do that.
Is it feasible to support this as a clang-specific attribute? For example, this would save the day:
```
template <typename T>
using [[clang::warn_unused_result]] SystemMaybe = std::expected<T, std::system_error>;
```
Thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VUGP4zYP_TXKhUjgyEkmOeSwM9ngG-BrUWAD9LigJSZWI0uGSCfr_vpCcmZ2sZ3eWsCwYYgiHx_fk5DZXQLRXq2f1foww0HamPYcMF07ZKE0a6Id9_93VwK1quy98eiujsAFaEV6VvUnpY9KHxPdHN154f2tW8R0Ufp4WFZ6qbXSL_AK2IGP8erCBSQChhAFhQDhRmkEE7suBqCUYoJEMqQAMvalTpeXLTXIBMigtC5on0O0jg0mq9aH_GidM3d4JXACnpjBuyv5EaRFeeRuMVifQVxIGM4xXaIIhYWqDqr6NL3_F-90o1RwK_3UgaAvwLGJgwBCoPvccQs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