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

    <tr>
        <th>Summary</th>
        <td>
            -Wunreachable-code-fallthrough doesn't work in templates
        </td>
    </tr>

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

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

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

<pre>
    Code:
```c++
int a(int x)
{
    switch (x)
    {
        case 1:
            return 2;
            [[fallthrough]];
        default:
            return 4;
    }
}

template<int b>
int a2(int x)
{
    switch (x)
    {
        case 1:
            return 2;
            [[fallthrough]];
        default:
            return 4;
    }
}

int c()
{
    return a(1) + a2<2>(3) + a2<4>(5);
}
```
Compile with -Wunreachable-code-fallthrough.

Expected result: Two warnings, one for each [[fallthrough]]. Or three, since the template is instantiated twice.

Actual result: One warning, in the untemplated function.

Compiler Explorer: https://godbolt.org/z/cWdoW5WvM

https://github.com/llvm/llvm-project/issues/18993#issuecomment-980927985 says

> (we currentyl don't warn on -Wunreachable-code on any templates because there was a concern that performance would be adversely affected by doing CFG work on lots of uninstantiated templates)

so this may be or have been intentional, but that comment is eight years old, so I'm not sure if it still applies. If it does apply, feel free to wontfix this one.

Found together with @StephanTLavavej on MSVC STL discord
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlVE2TmzgQ_TX40mUXCLDhwGHGE2-lKqkcZmrnLKTGKJElShL2sL9-W9jO2Ek2h72GEiA1rf5474nWyqnZWolJ_pCkT0n6kKzT8xAJe4xjtioTgCesiu-3hNUX383lM9DlTyqIHsjp3SHa75ziJbhHyL4nhJvLYRidAZbkjz9_TMpHGh3XOvTOjvs-KZ_i-NFXYsdHHX6XoLjblGyerv1cJ_Mz4GHQPBA229h3m-QfbtBgfxocsVkSRfXrfi-hokgy8qDGHyNG-ZZF2FiV3xmLs7GMs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