ObjC++ merge patch - @encode in templates

Nicola Pero nicola.pero@meta-innovation.com
Wed Oct 6 22:07:00 GMT 2010


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  <nicola.pero@meta-innovation.com>
+
+       Merge from 'apple/trunk' branch on FSF servers.
+       
+       2005-12-14  Fariborz Jahanian <fjahanian@apple.com>
+
+       Radar 4278774
+       * obj-c++.dg/encode-9.mm: New.
+       
 2010-10-06  Eric Botcazou  <ebotcazou@adacore.com>
 
        * 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 <string.h>           
+#include <stdlib.h>
+#include <objc/objc.h>
+
+template<typename T>
+class typeOf {
+public:
+    operator const char*() { return @encode(T); }
+};
+
+int main() {
+    typeOf<int> t;
+    if (strcmp ((const char *)t, @encode(int)))
+      abort();
+
+    typeOf<const char*> 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  <nicola.pero@meta-innovation.com>
+
+       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 <fjahanian@apple.com>
+
+       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 <fjahanian@apple.com>
+
+       Radar 4278774
+       * c-common.def: Add new expression code AT_ENCODE_EXPR.
+       
 2010-10-06  Eric Botcazou  <ebotcazou@adacore.com>
 
        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.  */





More information about the Gcc-patches mailing list