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

    <tr>
        <th>Summary</th>
        <td>
            Clarify support for exclusive_trylock_function annotation on constructors
        </td>
    </tr>

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

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

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

<pre>
    The [mutex demo](https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#mutex-h) in the Thread Safety Analysis documentation demonstrates a number of `MutexLocker` constructors that assume various properties about the given mutex, but it notably omits a constructor that performs `TryLock`, instead providing that as a method on `MutexLocker` itself.

In attempting to address [a bug related to a similar scoped lockable that tries to lock a given mutex](https://issues.chromium.org/issues/340196356) we considered the possibility of annotating the constructor with `exclusive_trylock_function(true)` and adding an implicit `operator bool()` that returns whether locking succeeded.

I'm not sure whether the analyzer *should* support something like this, but is it ever appropriate today to mark a constructor with `exclusive_trylock_function`, given that constructors don't return anything? If not, could we make it an error to help prevent misuse, similar to the way [it is prohibited on anything other than a function](https://github.com/llvm/llvm-project/blob/d665d51c9296fc0b57945bb67e06040e26cd03c5/clang/test/SemaCXX/warn-thread-safety-parsing.cpp#L750)?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVM1u2zgQfhr6MoghUz-2Dz6kDQwU6J6aQ2_FiBxZ3FCkQA6dep9-MXLsNosssHtJAJnz8fvjYM7uFIgOqv2k2qcVFh5jOuCMmXyj9aqP9nJ4HglU-2kqTD_B0hRV-6T0bmSes6oflT4qfTQew2nt_Xlax3RS-mijyUofn8dEaL_hQHx5DOgv2eX1yJNXul4QH0al9-AC8EhwPQ3X43A7DzaaMlFgZBfDQiFkTsiUASGUqacEcQDVVX8I5NdoXiiprgKzHCyGY8rAIzJgzmUiOGNysWSYU5wpsROkPhZeWJzcmQIs7JT-DH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