The following code compiles cleanly with GCC:
void func(int arg1, decltype(arg1) arg2) { (void)arg2; } int main(){}
I used this command to compile:
g++ -std=c++14 test.cpp -o test -pedantic-errors -Wall -Wextra
But such usage of a parameter in the middle of function declaration seems weird. Is it actually valid in standard C++, or is it a GCC extension?
This is fine. The ISO C++11 Standard
even gives your situation as an example.
First the parameter is in scope:
3.3.3 Block scope [ basic.scope.local ]
2 The potential scope of a function parameter name (including one appearing in a lambda-declarator) or of a function-local predefined variable in a function definition (8.4) begins at its point of declaration.
An example can be found here:
8.3.5 Functions [ dcl.fct ]
5 [ Note: This transformation does not affect the types of the parameters. For example, int(*)(const int p, decltype(p)*) and int(*)(int, const int*) are identical types. — end note ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With