aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-10-07 22:34:50 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-10-07 22:34:50 +0000
commitc154b3d8a1df6b4ae78e8388fc0a8bd1dbf48120 (patch)
tree455473998e5c9ec7c9dd8fd1ad23718ce9ad8d9b /gcc
parent2fb996b6d25fc277bc585e1a635c6e6c84492737 (diff)
downloadgcc-c154b3d8a1df6b4ae78e8388fc0a8bd1dbf48120.zip
gcc-c154b3d8a1df6b4ae78e8388fc0a8bd1dbf48120.tar.gz
gcc-c154b3d8a1df6b4ae78e8388fc0a8bd1dbf48120.tar.bz2
In gcc/testsuite/: 2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/testsuite/: 2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com> * obj-c++.dg/encode-10.mm: New testcase. In gcc/cp/: 2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com> * cp-tree.def: Changed type of AT_ENCODE_EXPR from tcc_unary to tcc_expression. * cxx-pretty-print.c (pp_cxx_unary_expression): Added case for AT_ENCODE_EXPR. * error.c (dump_expr): Added case for AT_ENCODE_EXPR. * pt.c (tsubst_copy): Added case for AT_ENCODE_EXPR. (value_dependent_expression_p): Added case for AT_ENCODE_EXPR. (type_dependent_expression_p): Added case for AT_ENCODE_EXPR. * parser.c (cp_parser_objc_encode_expression): Updated comment. From-SVN: r165138
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog12
-rw-r--r--gcc/cp/cp-tree.def2
-rw-r--r--gcc/cp/cxx-pretty-print.c8
-rw-r--r--gcc/cp/error.c8
-rw-r--r--gcc/cp/parser.c6
-rw-r--r--gcc/cp/pt.c8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/obj-c++.dg/encode-10.mm46
8 files changed, 93 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7e6bdda..b243c5a 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,15 @@
+2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * cp-tree.def: Changed type of AT_ENCODE_EXPR from tcc_unary to
+ tcc_expression.
+ * cxx-pretty-print.c (pp_cxx_unary_expression): Added case for
+ AT_ENCODE_EXPR.
+ * error.c (dump_expr): Added case for AT_ENCODE_EXPR.
+ * pt.c (tsubst_copy): Added case for AT_ENCODE_EXPR.
+ (value_dependent_expression_p): Added case for AT_ENCODE_EXPR.
+ (type_dependent_expression_p): Added case for AT_ENCODE_EXPR.
+ * parser.c (cp_parser_objc_encode_expression): Updated comment.
+
2010-10-07 Nicola Pero <nicola@nicola.brainstorm.co.uk>
Merge from apple/trunk branch on FSF servers.
diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def
index 1065c80..3f14a83 100644
--- a/gcc/cp/cp-tree.def
+++ b/gcc/cp/cp-tree.def
@@ -337,7 +337,7 @@ 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)
+DEFTREECODE (AT_ENCODE_EXPR, "at_encode_expr", tcc_expression, 1)
/* A STMT_EXPR represents a statement-expression during template
expansion. This is the GCC extension { ( ... ) }. The
diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c
index c3701c2..bbef227 100644
--- a/gcc/cp/cxx-pretty-print.c
+++ b/gcc/cp/cxx-pretty-print.c
@@ -791,6 +791,14 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, tree t)
pp_unary_expression (pp, TREE_OPERAND (t, 0));
break;
+ case AT_ENCODE_EXPR:
+ pp_cxx_ws_string (pp, "@encode");
+ pp_cxx_whitespace (pp);
+ pp_cxx_left_paren (pp);
+ pp_cxx_type_id (pp, TREE_OPERAND (t, 0));
+ pp_cxx_right_paren (pp);
+ break;
+
case NOEXCEPT_EXPR:
pp_cxx_ws_string (pp, "noexcept");
pp_cxx_whitespace (pp);
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index be3dd2c..185b361 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -2141,6 +2141,14 @@ dump_expr (tree t, int flags)
pp_cxx_right_paren (cxx_pp);
break;
+ case AT_ENCODE_EXPR:
+ pp_cxx_ws_string (cxx_pp, "@encode");
+ pp_cxx_whitespace (cxx_pp);
+ pp_cxx_left_paren (cxx_pp);
+ dump_type (TREE_OPERAND (t, 0), flags);
+ pp_cxx_right_paren (cxx_pp);
+ break;
+
case NOEXCEPT_EXPR:
pp_cxx_ws_string (cxx_pp, "noexcept");
pp_cxx_whitespace (cxx_pp);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f5fa793..f5f4521 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -21128,6 +21128,12 @@ cp_parser_objc_encode_expression (cp_parser* parser)
return error_mark_node;
}
+ /* This happens if we find @encode(T) (where T is a template
+ typename or something dependent on a template typename) when
+ parsing a template. In that case, we can't compile it
+ immediately, but we rather create an AT_ENCODE_EXPR which will
+ need to be instantiated when the template is used.
+ */
if (dependent_type_p (type))
{
tree value = build_min (AT_ENCODE_EXPR, size_type_node, type);
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 506bf9a..9afa74d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -11131,6 +11131,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
case ADDR_EXPR:
case UNARY_PLUS_EXPR: /* Unary + */
case ALIGNOF_EXPR:
+ case AT_ENCODE_EXPR:
case ARROW_EXPR:
case THROW_EXPR:
case TYPEID_EXPR:
@@ -17689,6 +17690,12 @@ value_dependent_expression_p (tree expression)
return dependent_type_p (expression);
return type_dependent_expression_p (expression);
+ case AT_ENCODE_EXPR:
+ /* An 'encode' expression is value-dependent if the operand is
+ type-dependent. */
+ expression = TREE_OPERAND (expression, 0);
+ return dependent_type_p (expression);
+
case NOEXCEPT_EXPR:
expression = TREE_OPERAND (expression, 0);
/* FIXME why check value-dependency? */
@@ -17806,6 +17813,7 @@ type_dependent_expression_p (tree expression)
if (TREE_CODE (expression) == PSEUDO_DTOR_EXPR
|| TREE_CODE (expression) == SIZEOF_EXPR
|| TREE_CODE (expression) == ALIGNOF_EXPR
+ || TREE_CODE (expression) == AT_ENCODE_EXPR
|| TREE_CODE (expression) == NOEXCEPT_EXPR
|| TREE_CODE (expression) == TRAIT_EXPR
|| TREE_CODE (expression) == TYPEID_EXPR
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 325ef76..13fbb7e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com>
+ * obj-c++.dg/encode-10.mm: New testcase.
+
+2010-10-07 Nicola Pero <nicola.pero@meta-innovation.com>
+
PR objc++/23614
* obj-c++.dg/lookup-2.mm: Do not assign 'nil' to a pointer to a
C++ class. Removed XFAIL.
diff --git a/gcc/testsuite/obj-c++.dg/encode-10.mm b/gcc/testsuite/obj-c++.dg/encode-10.mm
new file mode 100644
index 0000000..2b3af88
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/encode-10.mm
@@ -0,0 +1,46 @@
+/* Test for @encode in templates. */
+/* { dg-options "-lobjc" } */
+/* { dg-do run } */
+#include <string.h>
+#include <stdlib.h>
+
+template<typename T>
+const char *my_encode(int variant)
+{
+ const char *result;
+
+ switch (variant)
+ {
+ case 0:
+ result = @encode(T);
+ break;
+ case 1:
+ result = @encode(T*);
+ break;
+ case 2:
+ result = @encode(const T*);
+ break;
+ default:
+ result = @encode(int);
+ break;
+ }
+
+ return result;
+}
+
+int main()
+{
+ if (strcmp (@encode(char), my_encode<char>(0)))
+ abort ();
+
+ if (strcmp (@encode(char *), my_encode<char>(1)))
+ abort ();
+
+ if (strcmp (@encode(const char *), my_encode<char>(2)))
+ abort ();
+
+ if (strcmp (@encode(int), my_encode<char>(3)))
+ abort ();
+
+ return 0;
+}