From patchwork Sun Jul 7 00:22:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1957645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LJ0sIrf7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WGp024HK2z1xpP for ; Sun, 7 Jul 2024 10:24:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 59217388457F for ; Sun, 7 Jul 2024 00:23:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6E11D385C6C2 for ; Sun, 7 Jul 2024 00:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E11D385C6C2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6E11D385C6C2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720311807; cv=none; b=e5+yFyu1ZKJh5sPQM7zMyRl4lIfPYkYO8BGOEUwXX0EuUKXoJJFUYiJeQH60VYX2aZQGLQvigUBQgEFAUV0hWIeusVWvmUIsByluhZ6ZyOURK4jFXSUYH8Y6ZWFM3GYxt1N5kJFJcNpMxpHQMZG149L9i3W4Uq7FwXA+kOipYME= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720311807; c=relaxed/simple; bh=rYZn3vwRH2mNewHcJ8IgmZWLLgFPpXg1Zvdk4M6Wr14=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FA3BpmhBTiddCb5liQw7j5s8iH4sWn26l9sz+EOMGk3Y7k/eGfSUat0YmUHXC0txf1BX2FrYatseel02KyX+NeKlVq/7butHle15lBUkWbxXeBAlIvNZQcPF0Bq5yHUYbmAISeXZwETzYdQkpMATm8FYWvZFlP1RJU9OHulkGSg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720311768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=v8Kv+KQako8vJWohe2ECuzUhIqANcC4B3fzKX0UPwTU=; b=LJ0sIrf7wVENC18KVtkJCe4zEgNGIDNDmePcqif3Nrt3pc86ibTkDwJl4o/T7mFBxSAu/j XxQoCNZ8fKpkwziuvhINS/bs6lfzzvlJvV+4+sj2BcR/1ZThsMK4YAUSnx3uAYVBD3vhSi u6BrJdNZqpbpaFtreOwt8GN6JYqYKQg= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-RV7JE1SmP8Wu1gSI5cGVSg-1; Sat, 06 Jul 2024 20:22:47 -0400 X-MC-Unique: RV7JE1SmP8Wu1gSI5cGVSg-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6b5eb3a67d0so29774596d6.2 for ; Sat, 06 Jul 2024 17:22:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720311765; x=1720916565; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v8Kv+KQako8vJWohe2ECuzUhIqANcC4B3fzKX0UPwTU=; b=L2MIZex8dZ1jfky06I5qLvEjkO46m0zDjSSU8vtau/duDc7I+gN6w7sCSpPj9tRDvQ sYJo/gbK4Ck6zcUQR4CbmmY6ITSUY0ydH4JsW1Djful7SgW8eEHSqX+aDXuDmeflP/W9 SZ7Ea7UlrMyscgVSdfUcm/0sMFZWtvS68A6FA+JUNk6xQdbDekthZavFp0nzEl6H4wEx QKSXrfwBD7WRKnE7xShN9OntgHd+8dq5UZn3RxvKVn/Cj+xkmmehJWKLrDmtv4tx/E4h 2UsnaTpeVbA9UfBOE1LM3Op9KN7GLvc6BsVWe0Gp+BqZ4NBIvCqt347d+1pKNgzS9G8X nxHA== X-Gm-Message-State: AOJu0YyHPgwiOVB308KkxSAVyl96VZ5XRK9i3r2jhCV5e5+HiZxNFtqv kKPPLIR9BPMrsOQQw0V0LCcbPqDj7AVfXKHmquyn9rDS4uxjzBQbheQZh0sWJVUhEjUiJLWfHe6 Pi6vIav+totK+T8RIqhO0vn17wjyi+Ck7krHh9q/NjgkkAJQGxtIbOw3q0Y0cXDIZvnbl9/Oosr yn5/nNOXNn2Z6Z9Ccu57rQryD//dTt/Aw3tQvl X-Received: by 2002:ad4:594d:0:b0:6b5:4cb4:2eee with SMTP id 6a1803df08f44-6b5ed26c21fmr94381976d6.59.1720311765017; Sat, 06 Jul 2024 17:22:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfWvznEPPOPVsj0X9oHLb2e/Z7QW/QNbLOhEmSSsq/g9bmhuUj0Vxn0HtSE5/4xHhAo0c5oA== X-Received: by 2002:ad4:594d:0:b0:6b5:4cb4:2eee with SMTP id 6a1803df08f44-6b5ed26c21fmr94381866d6.59.1720311764573; Sat, 06 Jul 2024 17:22:44 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6b609a30706sm4921866d6.59.2024.07.06.17.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 17:22:44 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: xobj fn call without obj [PR115783] Date: Sat, 6 Jul 2024 20:22:42 -0400 Message-ID: <20240707002242.2511253-1-ppalka@redhat.com> X-Mailer: git-send-email 2.45.2.746.g06e570c0df MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14? -- >8 -- The code path for rejecting an object-less call to a non-static member function should also consider xobj member functions so that we properly reject the below calls with a "cannot call member function without object" diagnostic. PR c++/115783 gcc/cp/ChangeLog: * call.cc (build_new_method_call): Generalize METHOD_TYPE check to DECL_OBJECT_MEMBER_FUNCTION_P. gcc/testsuite/ChangeLog: * g++.dg/cpp23/explicit-obj-diagnostics11.C: New test. --- gcc/cp/call.cc | 2 +- .../g++.dg/cpp23/explicit-obj-diagnostics11.C | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 83070b2f633..41ef7562f27 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -11822,7 +11822,7 @@ build_new_method_call (tree instance, tree fns, vec **args, fn); } - if (TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE + if (DECL_OBJECT_MEMBER_FUNCTION_P (fn) && !DECL_CONSTRUCTOR_P (fn) && is_dummy_object (instance)) { diff --git a/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C new file mode 100644 index 00000000000..cc2571f62a2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/explicit-obj-diagnostics11.C @@ -0,0 +1,48 @@ +// PR c++/115783 +// { dg-do compile { target c++23 } } + +struct A { + int f(this auto); + + static void s() { + f(); // { dg-error "without object" } + } +}; + +int n = A::f(); // { dg-error "without object" } + +struct B { + void ns() { + A::f(); // { dg-error "without object" } + } + + static void s() { + A::f(); // { dg-error "without object" } + } +}; + +template +struct C { + void ns() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "without object" } + } + + static void s() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "without object" } + }; +}; + +template struct C; + +template +struct D : T { + void ns() { + A::f(); // { dg-error "without object" } + T::f(); // { dg-error "not a member of 'B'" } + } +}; + +template struct D; // { dg-message "required from here" } +template struct D; // { dg-bogus "required from here" }