Date: Mon, 12 Apr 2021 23:58:32 +0300
The following program compiled with gcc 9.3
#include <iostream>
void g( int x, int y = 20 )
{
std::cout << "x = " << x << ", y = " << y << '\n';
}
int main()
{
void g( int, int );
using ::g;
// void g( int, int );
g( 10 );
return 0;
}
issues error message
error: too few arguments to function ‘void g(int, int)’
g( 10 );
^
However this program
#include <iostream>
void g( int x, int y = 20 )
{
std::cout << "x = " << x << ", y = " << y << '\n';
}
int main()
{
// void g( int, int );
using ::g;
void g( int, int );
g( 10 );
return 0;
}
runs successfully.
I did not found in the section 9.9 The using declaration whether such a program is ill-formed or not.
The only text in the C++ 20 Standard that seems refers to this case is the quote in the section 12.2 Overloadable declarations
1 Not all function declarations can be overloaded. Those that cannot be overloaded are specified here. A program is ill-formed if it contains two such non-overloadable declarations in the same scope. [Note: This restriction applies to explicit declarations in a scope, and between such declarations and declarations made through a using-declaration (9.9). It does not apply to sets of functions fabricated as a result of name lookup (e.g., because of using-directives) or overload resolution (e.g., for operator functions). — end note]
Though the bold text is not clear enough and whether it indeed refers to the pointed case.
So a question arises are the both above programs ill-formed? And if so then why is there nothing said about this in the section 9.9 if I am not mistaken?
With best regards
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
#include <iostream>
void g( int x, int y = 20 )
{
std::cout << "x = " << x << ", y = " << y << '\n';
}
int main()
{
void g( int, int );
using ::g;
// void g( int, int );
g( 10 );
return 0;
}
issues error message
error: too few arguments to function ‘void g(int, int)’
g( 10 );
^
However this program
#include <iostream>
void g( int x, int y = 20 )
{
std::cout << "x = " << x << ", y = " << y << '\n';
}
int main()
{
// void g( int, int );
using ::g;
void g( int, int );
g( 10 );
return 0;
}
runs successfully.
I did not found in the section 9.9 The using declaration whether such a program is ill-formed or not.
The only text in the C++ 20 Standard that seems refers to this case is the quote in the section 12.2 Overloadable declarations
1 Not all function declarations can be overloaded. Those that cannot be overloaded are specified here. A program is ill-formed if it contains two such non-overloadable declarations in the same scope. [Note: This restriction applies to explicit declarations in a scope, and between such declarations and declarations made through a using-declaration (9.9). It does not apply to sets of functions fabricated as a result of name lookup (e.g., because of using-directives) or overload resolution (e.g., for operator functions). — end note]
Though the bold text is not clear enough and whether it indeed refers to the pointed case.
So a question arises are the both above programs ill-formed? And if so then why is there nothing said about this in the section 9.9 if I am not mistaken?
With best regards
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com
Received on 2021-04-12 15:58:38