]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/34267 (ICE applying __decltype to name of template class)
authorJakub Jelinek <jakub@redhat.com>
Thu, 29 Nov 2007 21:04:04 +0000 (22:04 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 29 Nov 2007 21:04:04 +0000 (22:04 +0100)
PR c++/34267
PR c++/34268
* parser.c (cp_parser_decltype): Don't call finish_id_expression
on ~type.
* semantics.c (finish_decltype_type): Issue error on types, TYPE_DECLs
and ~type early.

* g++.dg/cpp0x/decltype7.C: New test.
* g++.dg/cpp0x/decltype8.C: New test.

From-SVN: r130519

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/decltype7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/decltype8.C [new file with mode: 0644]

index ea87688d276f618588bd49699b9844a195f0eab8..3f7f9dc1fe9f2814b90958c43bd7a67ebb26d86d 100644 (file)
@@ -1,3 +1,12 @@
+2007-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34267
+       PR c++/34268
+       * parser.c (cp_parser_decltype): Don't call finish_id_expression
+       on ~type.
+       * semantics.c (finish_decltype_type): Issue error on types, TYPE_DECLs
+       and ~type early.
+
 2007-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/34181
index 8e16d22335ce1df3d1cce04ac1fced0af44639fb..7b173f0b7b23a58d3ef4fcd9fc306f65d75e9723 100644 (file)
@@ -8512,10 +8512,12 @@ cp_parser_decltype (cp_parser *parser)
                                      /*check_dependency=*/true,
                                      /*ambiguous_decls=*/NULL);
 
-      if (expr 
+      if (expr
           && expr != error_mark_node
           && TREE_CODE (expr) != TEMPLATE_ID_EXPR
           && TREE_CODE (expr) != TYPE_DECL
+         && (TREE_CODE (expr) != BIT_NOT_EXPR
+             || !TYPE_P (TREE_OPERAND (expr, 0)))
           && cp_lexer_peek_token (parser->lexer)->type == CPP_CLOSE_PAREN)
         {
           /* Complete lookup of the id-expression.  */
index 1ae7d0f7bbcfbf9e2d68b704697216befa0d16b3..381774ea1393fad03ab4fc8f167cb7c8b101c71f 100644 (file)
@@ -4066,6 +4066,15 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p)
   if (!expr || error_operand_p (expr))
     return error_mark_node;
 
+  if (TYPE_P (expr)
+      || TREE_CODE (expr) == TYPE_DECL
+      || (TREE_CODE (expr) == BIT_NOT_EXPR
+         && TYPE_P (TREE_OPERAND (expr, 0))))
+    {
+      error ("argument to decltype must be an expression");
+      return error_mark_node;
+    }
+
   if (type_dependent_expression_p (expr))
     {
       type = make_aggr_type (DECLTYPE_TYPE);
index 889d220f3ea8271ed52d12567b5626e3d967909d..c04a77fb1946629c8b781352089ac295c48440a0 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/34267
+       PR c++/34268
+       * g++.dg/cpp0x/decltype7.C: New test.
+       * g++.dg/cpp0x/decltype8.C: New test.
+
 2007-11-29  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/34248
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype7.C b/gcc/testsuite/g++.dg/cpp0x/decltype7.C
new file mode 100644 (file)
index 0000000..f757c9e
--- /dev/null
@@ -0,0 +1,14 @@
+// PR c++/34268
+// { dg-do compile }
+
+struct A
+{
+  __decltype (A);      // { dg-error "must be an expression" }
+  __decltype (~A);     // { dg-error "must be an expression" }
+};
+
+struct B
+{
+  __typeof__ (B);
+  __typeof__ (~B);     // { dg-error "expected primary-expression" }
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/decltype8.C b/gcc/testsuite/g++.dg/cpp0x/decltype8.C
new file mode 100644 (file)
index 0000000..3680689
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/34267
+// { dg-do compile }
+
+struct A {};
+__decltype (A);                // { dg-error "must be an expression" }
+template<int> struct B
+{
+  __decltype (A);      // { dg-error "must be an expression" }
+  __decltype (~A);     // { dg-error "must be an expression" }
+  __decltype (B);      // { dg-error "must be an expression" }
+  __decltype (~B);     // { dg-error "must be an expression" }
+};