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++17decltype
Your Answer
lock_outline
You need to log in to submit an answer.
Privacy & Cookie Consent
We use cookies to ensure the best experience on our website. This includes analytics, personalization, and marketing purposes. Some cookies are essential for the website to function properly.
By clicking "Accept", you consent to our use of cookies. You can read more about how we use cookies and how you can change your preferences in our Privacy Policy.