Nested constexpr-if statement in discarded branch is still evaluated? : <p>It appears to me that a constexpr-if statement that is inside the discarded branch of another constexpr-if statement is evaluated in MSVC (version 15.7.3).</p>

<p>Consider the following code:</p>

<pre><code>#include &lt;tuple&gt;
#include &lt;type_traits&gt;

template &lt;size_t I&gt;
int test() {
    if constexpr(I != 0) {
        return 0;
    }
    else { // This branch is discarded, but it seems that the constexpr-if below is still evaulated?
        if constexpr(std::is_same_v&lt;int, std::tuple_element_t&lt;I, std::tuple&lt;int&gt;&gt;&gt;) { // some constexpr check that is valid only when I == 0
            return 1;
        }
        else {
            return 2;
        }
    }
}

int main() {
    test&lt;1&gt;();
    return 0;
}
</code></pre>

<p>The code above fails to compile in MSVC, because <code>std::tuple_element_t</code> will fail a static assertion when <code>I</code> exceeds the bounds of the tuple.  This suggests that somehow the code in the discarded branch was evaluated as well, even though it is dependent on the template parameter <code>I</code>.</p>

<p>According to <a href="http://en.cppreference.com/w/cpp/language/if#Constexpr_If" rel="noreferrer">cppreference</a>, constexpr-if requires that "the discarded statement can't be ill-formed for every possible specialization", but I'm having a hard time deciding if this is the case here.</p>

<p>It also seems that GCC and Clang accepts this code without issue (tested on Compiler Explorer).</p>

<p>Is the compilation error acceptable by the C++ standard, or is MSVC non-compliant here?</p>

<p>(Also, if what I'm expecting the code to do isn't guaranteed by the standard, is there another way to accomplish nested constexpr-if statements?)</p>
