From patchwork Wed Oct 6 22:07:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 66983 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]) by ozlabs.org (Postfix) with SMTP id 731D7B70D4 for ; Thu, 7 Oct 2010 09:07:35 +1100 (EST) Received: (qmail 22913 invoked by alias); 6 Oct 2010 22:07:33 -0000 Received: (qmail 22893 invoked by uid 22791); 6 Oct 2010 22:07:32 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from smtp121.iad.emailsrvr.com (HELO smtp121.iad.emailsrvr.com) (207.97.245.121) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Oct 2010 22:07:27 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 15E33148242 for ; Wed, 6 Oct 2010 18:07:26 -0400 (EDT) Received: from dynamic9.wm-web.iad.mlsrvr.com (dynamic9.wm-web.iad1a.rsapps.net [192.168.2.216]) by smtp42.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 03C47148210 for ; Wed, 6 Oct 2010 18:07:26 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic9.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id B6F62320088 for ; Wed, 6 Oct 2010 18:07:25 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Thu, 7 Oct 2010 00:07:25 +0200 (CEST) Date: Thu, 7 Oct 2010 00:07:25 +0200 (CEST) Subject: ObjC++ merge patch - @encode in templates From: "Nicola Pero" To: "GCC Patches" MIME-Version: 1.0 X-Type: plain Message-ID: <1286402845.74812782@192.168.2.229> X-IsSubscribed: yes 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 I committed this ObjC++ merge from the apple/trunk branch (pre-approved by Mike Stump). It makes @encode() work in C++ templates (at least in the included testcase). Thanks Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 165061) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2010-10-06 Nicola Pero + + Merge from 'apple/trunk' branch on FSF servers. + + 2005-12-14 Fariborz Jahanian + + Radar 4278774 + * obj-c++.dg/encode-9.mm: New. + 2010-10-06 Eric Botcazou * g++.dg/cpp0x/pr45908.C: New test. Index: testsuite/obj-c++.dg/encode-9.mm =================================================================== --- testsuite/obj-c++.dg/encode-9.mm (revision 0) +++ testsuite/obj-c++.dg/encode-9.mm (revision 0) @@ -0,0 +1,26 @@ +/* Test than @encode is properly instantiated. */ +/* { dg-options "-lobjc" } */ +/* { dg-do run } */ + +#include +#include +#include + +template +class typeOf { +public: + operator const char*() { return @encode(T); } +}; + +int main() { + typeOf t; + if (strcmp ((const char *)t, @encode(int))) + abort(); + + typeOf c; + if (strcmp ((const char *)c, @encode(const char*))) + abort(); + + return 0; +} + Index: cp/ChangeLog =================================================================== --- cp/ChangeLog (revision 165061) +++ cp/ChangeLog (working copy) @@ -1,3 +1,21 @@ +2010-10-06 Nicola Pero + + Merge from apple/trunk branch on FSF servers. + * cp-tree.def: Added AT_ENCODE_EXPR here instead of to the no + longer existing gcc/c-common.def. + + 2005-12-14 Fariborz Jahanian + + Radar 4278774 + * pt.c (tsubst_copy_and_build): Instantiate @endcode(T). + * parser.c (cp_parser_objc_encode_expression): Build a templatized + parse tree for @encode(T). + + 2005-12-14 Fariborz Jahanian + + Radar 4278774 + * c-common.def: Add new expression code AT_ENCODE_EXPR. + 2010-10-06 Eric Botcazou PR c++/45908 Index: cp/pt.c =================================================================== --- cp/pt.c (revision 165061) +++ cp/pt.c (working copy) @@ -12359,6 +12359,19 @@ tsubst_copy_and_build (tree t, return cxx_sizeof_or_alignof_expr (op1, TREE_CODE (t), complain & tf_error); + case AT_ENCODE_EXPR: + { + op1 = TREE_OPERAND (t, 0); + ++cp_unevaluated_operand; + ++c_inhibit_evaluation_warnings; + op1 = tsubst_copy_and_build (op1, args, complain, in_decl, + /*function_p=*/false, + /*integral_constant_expression_p=*/false); + --cp_unevaluated_operand; + --c_inhibit_evaluation_warnings; + return objc_build_encode_expr (op1); + } + case NOEXCEPT_EXPR: op1 = TREE_OPERAND (t, 0); ++cp_unevaluated_operand; Index: cp/parser.c =================================================================== --- cp/parser.c (revision 165061) +++ cp/parser.c (working copy) @@ -21128,6 +21128,13 @@ cp_parser_objc_encode_expression (cp_parser* parse return error_mark_node; } + if (dependent_type_p (type)) + { + tree value = build_min (AT_ENCODE_EXPR, size_type_node, type); + TREE_READONLY (value) = 1; + return value; + } + return objc_build_encode_expr (type); } Index: cp/cp-tree.def =================================================================== --- cp/cp-tree.def (revision 165061) +++ cp/cp-tree.def (working copy) @@ -335,6 +335,10 @@ DEFTREECODE (ARROW_EXPR, "arrow_expr", tcc_express expansion. */ DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", tcc_expression, 1) +/* Represents an Objective-C++ '@encode' expression during template + expansion. */ +DEFTREECODE (AT_ENCODE_EXPR, "at_encode_expr", tcc_unary, 1) + /* A STMT_EXPR represents a statement-expression during template expansion. This is the GCC extension { ( ... ) }. The STMT_EXPR_STMT is the statement given by the expression. */