<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/108095>108095</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [[maybe_unused]] attribute used inside a template argument specifying a type of a function causes a compilation error
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jarzec
      </td>
    </tr>
</table>

<pre>
    If a specification of a type of a function in a template argument uses the `[[maybe_unused]]` attribute an error is raised - the initial `[` is interpreted as a beginning of a lambda capture.
This description is quite a mouthful, so let me give an example. The following code:
```
//...
std::function<int([[maybe_unused]] int)> f = fun;
//...
```
Causes the following error:
```
<source>:9:24: error: expected variable name or 'this' in lambda capture list
    9 | std::function<int([[maybe_unused]] int)> f = fun;
      | ^
<source>:11:2: error: expected '>'
   11 | }
      | ^
<source>:9:18: note: to match this '<'
    9 | std::function<int([[maybe_unused]] int)> f = fun;
      | ^
<source>:11:2: error: expected unqualified-id
   11 | }
      | ^
<source>:11:2: error: expected '}'
<source>:8:1: note: to match this '{'
    8 | {
      | ^
4 errors generated.
Compiler returned: 1
```
The quoted error is for **x86-64 clang 18.1.0** from [godbolt](https://godbolt.org/z/6YoPnYcsj), but it is almost identical for all versions (at least) since 12.0.0.

I agree the [[maybe_unused]] attribute makes little sense in the presented context. However, at least to my understanding, the mentioned example is valid C++ syntax. I also believe a valid use case where it should be accepted is generated code. This, in fact, is how the issue was identified.
Other compilers (GCC and MSVC) correctly compile the code.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMlk2P2zYTxz8NfRmsIFGyZR98sLXx8-RQtECDAjkVI3JsMaVIhaS863z6YiTtJlnspgXaQw3Blvky858fh0NijObiiPZifRTr-xWOqfNh_wnDF1Kr1uvb_v0ZEOJAypyNwmS8A89N6TbQ_HYenZrajeN26geLiQDDZezJJ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