<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:antons.jelkins@bmw.de" title="Antons Jeļkins <antons.jelkins@bmw.de>"> <span class="fn">Antons Jeļkins</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - Meyers' singleton does not work with [[gnu::const]] and -O1 to -O3"
   href="https://bugs.llvm.org/show_bug.cgi?id=36750">bug 36750</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>INVALID
           </td>
           <td>---
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>RESOLVED
           </td>
           <td>REOPENED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - Meyers' singleton does not work with [[gnu::const]] and -O1 to -O3"
   href="https://bugs.llvm.org/show_bug.cgi?id=36750#c4">Comment # 4</a>
              on <a class="bz_bug_link 
          bz_status_REOPENED "
   title="REOPENED - Meyers' singleton does not work with [[gnu::const]] and -O1 to -O3"
   href="https://bugs.llvm.org/show_bug.cgi?id=36750">bug 36750</a>
              from <span class="vcard"><a class="email" href="mailto:antons.jelkins@bmw.de" title="Antons Jeļkins <antons.jelkins@bmw.de>"> <span class="fn">Antons Jeļkins</span></a>
</span></b>
        <pre>I will reword this bug to say gnu::pure and then reopen it.

Reasoning:

Neither gnu::pure nor gnu::const are defined by the C++ standard. These are
implementation specific attributes defined here [1].

[1]
<a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes">https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#Common-Function-Attributes</a>

It says that gnu::pure should be used if a function has no effects except the
return value and its return value depends only on the parameters and/or global
variables.

It says that a function annotated with gnu::pure can be subject to common
subexpression elimination and loop optimization just as an arithmetic operator
would be, and it is safe to call it fewer times than the program says.

I would like also to quote a GCC developer [2]:

<span class="quote">> But if we are allowed to DCE a lazy_i call with unused result then it
> really is "pure". Basically with this property we consider the static
> variable it writes to as local, as it cannot be inspected in any other
> way than by calling the function or inspecting its return value.</span >

[2] <a href="https://gcc.gnu.org/ml/gcc/2012-10/msg00029.html">https://gcc.gnu.org/ml/gcc/2012-10/msg00029.html</a>

Summarising the said above, gnu::pure does not require a function not to have
side-effects in so strict sense. Static local variables are fine. Thus the
optimisation performed by clang is invalid and the MyClass object must be
constructed.</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>