From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 31E2E3858D20; Sun, 14 Jan 2024 16:51:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 31E2E3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705251109; bh=/SbVXVmMU98EOzp6nMisteSl/lKuFxngF7QpQB+KQSE=; h=From:To:Subject:Date:From; b=rjHl6l03UeOUvHNtCa96y8ysY7MNKzujGYFDsHD1C3m7LwmFzStrWjXoMijYCRjzo EPiY54tIjprNCY9+qHSoTVlYMHGw5V/WRDqdoPcQaq9JoFEY1/R4hpe5aHJYdxvuBT TsohtHXrTjLf0GFzI/m2SXNiKzz56SxQ3qfuIZZo= From: "cooky.ykooc922 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113388] New: Calling explicit object member function without object argument inside a function that is not an implicit object member function Date: Sun, 14 Jan 2024 16:51:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cooky.ykooc922 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113388 Bug ID: 113388 Summary: Calling explicit object member function without object argument inside a function that is not an implicit object member function Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cooky.ykooc922 at gmail dot com Target Milestone: --- According to https://eel.is/c++draft/over.call.func#3: In unqualified function calls, the function is named by a primary-expressio= n. The function declarations found by name lookup ([basic.lookup]) constitute = the set of candidate functions. Because of the rules for name lookup, the set of candidate functions consists either entirely of non-member functions or entirely of member functions of some class T. In the former case or if the primary-expression is the address of an overload set, the argument list is = the same as the expression-list in the call. Otherwise, the argument list is the expression-list in the call augmented by the addition of an implied object argument as in a qualified function call. If the current class is, or is derived from, T, and the keyword this ([expr.prim.this]) refers to it, then= the implied object argument is (*this). Otherwise, a contrived object of type T becomes the implied object argument; if overload resolution selects a non-static member function, the call is ill-formed. In other words, the code snippet below must produce an error because a call= to 'bar()' inside the function 'foo', 'baz', or any function which is not an implicit object member function itself, is ill-formed without the object argument. There is no error inside implicit object member function 'qux' because the implied object argument is '*this' unlike other explicit object member functions. struct A { void bar(this A) {} static void foo() { // not ok: this should be error // because the overload resolution // picked a non-static member function // without an object argument bar(); // ok [error as expected]: // bar(A{}); // ok [converted to function pointer]: (&A::bar)(A{}); // ok [called with an object argument]: A{}.bar(); } void baz(this A self) { // ok self.bar(); // ok [error as expected] // self.bar(self); // ok [error as expected] // bar(A{}); // not ok: this should be error // because the overload resolution // picked a non-static function // without an object argument // even inside the scope of the // explicit object member function bar(); // ok A{}.bar(); } void qux() { // ok bar(); // ok [error as expected] // bar(*this); } }; godbolt link with -std=3Dc++23: https://godbolt.org/z/89Msa7Gfj=