From patchwork Wed Mar 27 02:56:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 231584 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 16B442C008C for ; Wed, 27 Mar 2013 13:57:20 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=JtZL3Oht7GbTgVAqLgqP/djjgRs7Nd1t0x6bhxQqYAHAUV 81Y0tB1NE+wGibkqboP8EmdNs96LeA0AF5dr6vmAQuE18HJA0UaUZ0w4xI35ppft 1EYA8Of7RJ5LrBJI8nlMQBf912/soxYYFFAy8RxCEne26UV3JCIcBqNpuqua4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=T5dnX7pKSec+kpIZA2N4uLHAbyg=; b=Enskn1gzTxCWtsn+EE5E 3qvBCtDsx1pJwIqw0jFIwzvcrcb5wuCkxnzK+030mP3Jh3k32/Lqcv6fdTGngo9q w13oD0xw+u+95N7cipZCP1FNYFajPzB+pVV4ERMAc5LVf2Dbvho7RjghFUpAYKLS v4BcQCU2NpTROhoUD9d3EkM= Received: (qmail 26924 invoked by alias); 27 Mar 2013 02:57:10 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 26912 invoked by uid 89); 27 Mar 2013 02:57:02 -0000 X-Spam-SWARE-Status: No, score=-7.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 27 Mar 2013 02:56:59 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2R2uvdL032573 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Mar 2013 22:56:57 -0400 Received: from [10.3.113.57] (ovpn-113-57.phx2.redhat.com [10.3.113.57]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2R2urbm015033 for ; Tue, 26 Mar 2013 22:56:57 -0400 Message-ID: <51525FF5.5070504@redhat.com> Date: Tue, 26 Mar 2013 22:56:53 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:21.0) Gecko/20100101 Thunderbird/21.0a2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/52597 (misleading diagnostic for wrong use of member function) X-Virus-Found: No When we see a use of a non-overloaded non-static member function, we give the resulting expression unknown type so that invalid uses get errors. But the "can't resolve overloading" error is wrong in this case, so we should give the right one. Tested x86_64-pc-linux-gnu, applying to trunk. commit fa430ccf08f60e0affd935854fd8b49f547d21a4 Author: Jason Merrill Date: Tue Mar 26 14:26:29 2013 -0400 PR c++/52597 * typeck.c (invalid_nonstatic_memfn_p): Use get_first_fn. Take tree. * semantics.c (finish_decltype_type): Check it before type_unknown_p. * cp-tree.h: Adjust prototype. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4018685..36671d5 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5988,7 +5988,7 @@ extern tree build_typed_address (tree, tree); extern tree build_nop (tree, tree); extern tree non_reference (tree); extern tree lookup_anon_field (tree, tree); -extern bool invalid_nonstatic_memfn_p (const_tree, tsubst_flags_t); +extern bool invalid_nonstatic_memfn_p (tree, tsubst_flags_t); extern tree convert_member_func_to_ptr (tree, tree, tsubst_flags_t); extern tree convert_ptrmem (tree, tree, bool, bool, tsubst_flags_t); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 127e2da..8cf7886 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -5276,16 +5276,16 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p, expr = resolve_nondeduced_context (expr); - if (type_unknown_p (expr)) - { - if (complain & tf_error) - error ("decltype cannot resolve address of overloaded function"); - return error_mark_node; - } - if (invalid_nonstatic_memfn_p (expr, complain)) return error_mark_node; + if (type_unknown_p (expr)) + { + if (complain & tf_error) + error ("decltype cannot resolve address of overloaded function"); + return error_mark_node; + } + /* To get the size of a static data member declared as an array of unknown bound, we need to instantiate it. */ if (TREE_CODE (expr) == VAR_DECL diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 4e42a9d..8778b2c 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1766,9 +1766,16 @@ cxx_alignas_expr (tree e) violates these rules. */ bool -invalid_nonstatic_memfn_p (const_tree expr, tsubst_flags_t complain) +invalid_nonstatic_memfn_p (tree expr, tsubst_flags_t complain) { - if (expr && DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) + if (expr == NULL_TREE) + return false; + /* Don't enforce this in MS mode. */ + if (flag_ms_extensions) + return false; + if (is_overloaded_fn (expr) && !really_overloaded_fn (expr)) + expr = get_first_fn (expr); + if (DECL_NONSTATIC_MEMBER_FUNCTION_P (expr)) { if (complain & tf_error) error ("invalid use of non-static member function"); diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype50.C b/gcc/testsuite/g++.dg/cpp0x/decltype50.C new file mode 100644 index 0000000..dc3332a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/decltype50.C @@ -0,0 +1,18 @@ +// PR c++/52597 +// { dg-require-effective-target c++11 } + +struct A { + int zip(); + + decltype(zip) bar0; // { dg-error "invalid use of non-static member function" } + void bar1() { + typedef decltype(this->A::zip) x; // { dg-error "invalid use of non-static member function" } + } + void bar2() { + typedef decltype(A::zip) x; // { dg-error "invalid use of non-static member function" } + } +}; + +typedef decltype(A().zip) x; // { dg-error "invalid use of non-static member function" } + +// { dg-prune-output "invalid type in declaration" } diff --git a/gcc/testsuite/g++.dg/template/overload6.C b/gcc/testsuite/g++.dg/template/overload6.C index 5e26c44..8d574e7 100644 --- a/gcc/testsuite/g++.dg/template/overload6.C +++ b/gcc/testsuite/g++.dg/template/overload6.C @@ -4,7 +4,7 @@ // PR 21592:ICE // Origin: Volker Reichelt -template void unique(T,T); // { dg-message "note" } +template void unique(T,T); struct A { @@ -13,6 +13,5 @@ struct A template void foo() { - unique(A().begin); // { dg-error "no matching function" "" } - // { dg-message "candidate" "candidate note" { target *-*-* } 16 } + unique(A().begin); // { dg-error "invalid use of non-static member function" } } diff --git a/gcc/testsuite/g++.dg/template/ptrmem4.C b/gcc/testsuite/g++.dg/template/ptrmem4.C index 14f36d4..0765032 100644 --- a/gcc/testsuite/g++.dg/template/ptrmem4.C +++ b/gcc/testsuite/g++.dg/template/ptrmem4.C @@ -6,7 +6,7 @@ // Pointer to member function template argument deduction ICE. -template void queryAliases(CONT& fill_me); // { dg-message "queryAliases|no known conversion" } +template void queryAliases(CONT& fill_me); struct SpyExample { @@ -16,5 +16,5 @@ struct SpyExample void SpyExample::ready() { - queryAliases(inputs); // { dg-error "matching|unresolved" } + queryAliases(inputs); // { dg-error "invalid" } } diff --git a/gcc/testsuite/g++.old-deja/g++.mike/p11110.C b/gcc/testsuite/g++.old-deja/g++.mike/p11110.C index 7e3a1ff..714f628 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/p11110.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/p11110.C @@ -6,7 +6,7 @@ class data; class conatiner { public: virtual void* first (); - virtual data* contents (void* i); // { dg-message "conatiner::contents|no known conversion" } + virtual data* contents (void* i); }; class user { @@ -17,6 +17,5 @@ private: }; data* user::data1() const { - return (_c.contents (_c.first)); // { dg-error "match" } - // { dg-message "candidate" "candidate note" { target *-*-* } 20 } + return (_c.contents (_c.first)); // { dg-error "invalid use of non-static member function" } }