constexpr-if(false) vs two phase name lookup

99 views Asked by At

void func4();

template<typename T>
void test(T t) {
    if constexpr(false) {
        func1(t);      // #1 OK
        //func2();     // #2 Error
        //::func3(t);  // #3 Error
        ::func4(t);    // #4 OK??
    }
}

int main() {
  test(0);
}

https://godbolt.org/z/K1c7WW8sG

TLDR: Is #4 well-defined or something else?

If I understand correctly,

  • #1 is ok because func1(t) is dependent on t and might need to look up with ADL in 2nd phase, which doesn't happen because if constexpr(false) is not dependent and is not instantiated (see Does "if constexpr(something false)" ALWAYS omit template instantiation),
  • #2 is error because func2() is not dependent and needs a declaration in 1st phase,
  • #3 is error because qualified ::func3(t) is not dependent and needs a declaration in namespace :: in 1st phase.

However, a declaration of ::func4 exists but with a signature that cannot be called at #4. All three big compilers accept it. I wonder if it is well-defined or something else.

0

There are 0 answers