Unused parameter warning in templated function with if constexpr
We can say that the parameter a is not fully unused, it's conditionally unused.
The C++ standard requires to generate diagnostic messages for ill-formed programs. Your program is not ill-formed. The C++ standard does not require compilers to generate other warnings at all. So it's up to the compiler vendor to decide how to implement that.
While I personally would like to be warned about conditionally unused variables (your example is a good demo why), no compiler vendor has implemented that. Why? They test new version of compilers on large code bases to see whether new C++ features will cause breaking changes. Likely, during those tests, a lot of warnings were generated for code like yours, but the code was considered totally fine by C++ experts. So the warnings were adapted to not occur in such situations. That's to ensure that code with 0 warnings is possible.

In this code
#include <type_traits>
#include <iostream>

template <class T>
void func(const T& a)
{
    if constexpr(std::is_same_v<T,int>)
    {
        static_cast<void>(a);
    }
    else if constexpr(std::is_same_v<T,double>)
    {
        // oops forgot to use it here   
    }
    else
    {
        
    }
}

int main() {
    func(4);
    func("this");
}

why doesn't the compiler warn about unused variable in the else-s()? (with -Wall)
My understanding is that logically the instantiations of the method are completely different. If the argument is not being used in one of the instantiations of the template, isn't it an unused variable?
Or does the language/compiler not interpret it like that.
