<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [[likely]]/[[unlikely]] is sensitive to surrounding braces"
   href="https://bugs.llvm.org/show_bug.cgi?id=50275">50275</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[[likely]]/[[unlikely]] is sensitive to surrounding braces
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++2a
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aw1621107@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example adapted from the example code in the standard  (section 9.12.6)
(<a href="https://godbolt.org/z/58bxzo8oW">https://godbolt.org/z/58bxzo8oW</a>):

    void g(int);
    int f(int n) {
        if (n > 5) [[unlikely]] {
            g(0);
            return n * 2 + 1;
        } else {
            g(1);
            return n * 5;
        }
    }

The clang-tidy readability-braces-around-statements check (and the hicpp/google
equivalents) triggers here, and suggests adding braces before the attribute:

    <source>:3:15: warning: statement should be inside braces
[readability-braces-around-statements]
        if (n > 5) [[unlikely]] {
                  ^
                   {
    1 warning generated.

However, inserting the braces as suggested results in the attribute having no
effect on the generated assembly.

The assembly produced by GCC 11.1, for comparison, does depend on the
presence/absence of [[unlikely]] regardless of the presence of the extra
braces.

I'm not entirely sure whether clang-tidy's warning here is correct, but the
presence/absence of braces affecting generated code here seems unintuitive.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>