Why decltype applied to a function discards const qualifiers from input parameters?
11:03 12 May 2026

For example this code snippet:

#include 

int func_1(const bool)
{
    return 0;
}

int func_2(const bool &)
{
    return 0;
}

int main() {
    static_assert(std::is_same_v);
    static_assert(std::is_same_v);
    return 0;
}

produces this error messages:

:14:19: error: static assertion failed due to requirement 'std::is_same_v'
   14 |     static_assert(std::is_same_v);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:15:19: error: static assertion failed due to requirement 'std::is_same_v'
   15 |     static_assert(std::is_same_v);
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

as we can see decltype(func_1) discarded const qualifier from const bool input parameter but preserved it for func_2.

Why this is so? And is there a way to get input parameter types as they are declared in function prototype(without dropping qualifiers)?

c++ c++17 decltype