Are there extensions to let optimizers assume const-ref parameters will stay const? : <p>Related to my former question: <a href="https://stackoverflow.com/questions/49117489/are-compilers-not-allowed-to-assume-const-ref-parameters-will-stay-const">Are compilers not allowed to assume const-ref parameters will stay const?</a></p>

<p>My new question is: Is there compiler-specific, non-standard extensions or syntax to tell GCC/Clang/MSVC that an object is not writable? For example, here's some fake-ish code I'd like to be able to write:</p>

<pre><code>void f(const int&amp; i) {

    // At this point, compiler doesn't know if "i" can be mutated or not,
    // so it assumes it can

    // Fake-ish -- compiler now assumes "i" cannot be mutated and optimizes accordingly
    __assume(readonly i);

    // ...

}
</code></pre>
