From patchwork Fri Jun 14 13:41:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 251432 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 8CE632C0040 for ; Fri, 14 Jun 2013 23:41:16 +1000 (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:cc:subject:content-type; q=dns; s=default; b=US9t+iDih51pqCMLqFZSH/LdXpxOchhPnDUvldfRtk1 3a2/aGhrPefjCv89rebo842HLgdtNAfoJLT8MG9ijyHdOqw2wA17sbDvwnTELXcL XbcoAxV8rdDzKa5gFfFGrN/kNh7TaC2XXA/9tNO9oQbxODjk/hNy2Bt4Dq4fcO/Q = 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:cc:subject:content-type; s=default; bh=UE4WYDnRKR0V92TvMWl2H6WHdkw=; b=h+NVokY48jvGkr9Dy 3JNN4sZmaF3UO3oK8uyIgLS5VXhfGdG03G/zCIFFF+2ebYO9u/MkqCjYNIcTgBcP /P1alOsaLyFfLVpJt2YizEoo55bunlU5n5eIwqX+KrIjqQrh5uz9rDZFrRCrQcSZ TeobAdG6nWRAjgDAxoLfpXqsv4= Received: (qmail 5452 invoked by alias); 14 Jun 2013 13:41:09 -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 5442 invoked by uid 89); 14 Jun 2013 13:41:08 -0000 X-Spam-SWARE-Status: No, score=-5.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_HOSTKARMA_NO, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Fri, 14 Jun 2013 13:41:07 +0000 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r5EDf2sE021159 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 14 Jun 2013 13:41:03 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5EDf4kB006388 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 14 Jun 2013 13:41:04 GMT Received: from abhmt114.oracle.com (abhmt114.oracle.com [141.146.116.66]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r5EDf3NM013248; Fri, 14 Jun 2013 13:41:03 GMT Received: from poldo4.casa (/79.52.234.152) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 14 Jun 2013 06:41:03 -0700 Message-ID: <51BB1D6D.8080405@oracle.com> Date: Fri, 14 Jun 2013 15:41:01 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 51413 X-Virus-Found: No Hi, maybe we can resolve this one too, it remained assigned to me too much time. Currently the diagnostic is completely broken: cannot apply ‘offsetof’ to member function ‘#‘indirect_ref’ not supported by dump_decl#’ Given the usual issues with prettyprinting expressions, I think we can still make good progress along the way of the below (which is also quite close to what ICC does, for example). What do you think? I took the wording directly from the documentation. Tested x86_64-linux. Thanks, Paolo. ////////////////////// /cp 2013-06-14 Paolo Carlini PR c++/51413 * semantics.c (finish_offsetof): Handle INDIRECT_REF as expr. /testsuite 2013-06-14 Paolo Carlini PR c++/51413 * g++.dg/ext/builtin-offsetof1.C: New. Index: cp/semantics.c =================================================================== --- cp/semantics.c (revision 200088) +++ cp/semantics.c (working copy) @@ -3690,10 +3690,17 @@ finish_offsetof (tree expr) || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE || TREE_TYPE (expr) == unknown_type_node) { - if (TREE_CODE (expr) == COMPONENT_REF - || TREE_CODE (expr) == COMPOUND_EXPR) - expr = TREE_OPERAND (expr, 1); - error ("cannot apply % to member function %qD", expr); + if (TREE_CODE (expr) == INDIRECT_REF) + error ("second operand of % is neither a single " + "identifier nor a sequence of member accesses and " + "array references"); + else + { + if (TREE_CODE (expr) == COMPONENT_REF + || TREE_CODE (expr) == COMPOUND_EXPR) + expr = TREE_OPERAND (expr, 1); + error ("cannot apply % to member function %qD", expr); + } return error_mark_node; } if (REFERENCE_REF_P (expr)) Index: testsuite/g++.dg/ext/builtin-offsetof1.C =================================================================== --- testsuite/g++.dg/ext/builtin-offsetof1.C (revision 0) +++ testsuite/g++.dg/ext/builtin-offsetof1.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/51413 +// { dg-options "-w" } + +struct A +{ + static void foo(); +}; + +int i = __builtin_offsetof(A, foo[1]); // { dg-error "neither a single identifier nor a sequence of member accesses and array references" }