<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 - A mutable member inhibits constant propagation"
   href="https://bugs.llvm.org/show_bug.cgi?id=51599">51599</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>A mutable member inhibits constant propagation
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

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

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

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

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the following code:

```
struct X
{
    int a;
    mutable int b;
};

inline constexpr X instance{ 1, 2 };

constexpr X const & get() noexcept
{
    return instance;
}

constexpr int f1( X const& x )
{
    return x.a;
}

int f2()
{
    return f1( get() );
}

int f3()
{
    constexpr auto r = f1( get() );
    return r;
}
```

`f3` correctly returns a constant because `f1( get() )` is forcibly evaluated
as a constant expression, but `f2` does not:

```
f2():                                 # @f2()
        mov     eax, dword ptr [rip + instance]
        ret
f3():                                 # @f3()
        mov     eax, 1
        ret
        .section        .data.instance,"aGw",@progbits,instance,comdat
instance:
        .long   1                               # 0x1
        .long   2                               # 0x2
```
(<a href="https://godbolt.org/z/Yvs4GK7Yr">https://godbolt.org/z/Yvs4GK7Yr</a>)
(GCC has no problems: <a href="https://godbolt.org/z/Mr5e863E3">https://godbolt.org/z/Mr5e863E3</a>)

This is simplified from code using Boost.System 1.77, where the inability to
figure out that e.g. `system_category()` returns the system category causes
much worse codegen in situations such as `error_code(5, system_category())`.</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>