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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Unexpected match for the `CompoundStmt` with zero elements
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          tomasz-kaminski-sonarsource
      </td>
    </tr>
</table>

<pre>
    For the following code snippet the matcher `compoundStmt(statementCountIs(0))` returns two matches, with the source locations pointing to return statement (live example [here](https://godbolt.org/z/eKn4rv6ce))
```c++
template<int N>
int ifConstexprTemplate() {
  if constexpr (N > 10) return 1;
  // ^~~~~~
  else return 2;
  // ^~~~~~
}

void instantiateIfConstexpr() {
 ifConstexprTemplate<5>();
  ifConstexprTemplate<11>();
}
```
This is very unexpected and makes it difficult to investigate and fix regression in the tools that rely on the AST matches.

This is a regression introduced by the https://github.com/llvm/llvm-project/commit/a26cc759ae5a8018e2c328cf53173992340b995a commit, that represents the discarded branches of the `if constexpr` or `if consteval` with the empty `CompoundStmt`. Example AST:
```
IfStmt <line:4:3, line:5:15> has_else constexpr
|-ConstantExpr <line:4:17, col:21> 'bool'
| |-value: Int 0
| `-BinaryOperator <col:17, col:21> 'bool' '>'
|   |-SubstNonTypeTemplateParmExpr <col:17> 'int'
|   | |-NonTypeTemplateParmDecl <line:1:10, col:14> col:14 referenced 'int' depth 0 index 0 N
|   | `-IntegerLiteral <line:4:17> 'int' 5
| `-IntegerLiteral <col:21> 'int' 10
|-CompoundStmt <col:25, col:32>  // <-- Matched compound stm
 `-ReturnStmt <line:5:8, col:15>
 `-IntegerLiteral <col:15> 'int' 2
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVVFv6zYP_TXKC5FClmzHfshDmjZA8X3rhrV7HhSbTrQrS4ZE57b3Yb99kBInaVPcYY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