C++ Logo

std-discussion

Advanced search

Re: The using declaration and function default arguments.

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Tue, 13 Apr 2021 22:41:01 +0800
Ha, it is interesting that the three major compilers all behave
differently. As you described, GCC accepts one program and rejects the
other. Clang accepts both. MSVC rejects both, with error messages like
"C2884: 'g': introduced by using-declaration conflicts with local function
'g'".

On Tue, 13 Apr 2021 at 04:59, Vladimir Grigoriev via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> 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
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


-- 
Yongwei Wu
URL: http://wyw.dcweb.cn/

Received on 2021-04-13 09:41:17