]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/23797 (ICE on typename outside template)
authorVolker Reichelt <reichelt@igpm.rwth-aachen.de>
Wed, 16 Nov 2005 13:03:13 +0000 (13:03 +0000)
committerVolker Reichelt <reichelt@gcc.gnu.org>
Wed, 16 Nov 2005 13:03:13 +0000 (13:03 +0000)
Backport from mainline:
2005-10-12  Nathan Sidwell  <nathan@codesourcery.com>

PR c++/23797
* parser.c (cp_parser_functional_cast): Cope when TYPE is not a
TYPE_DECL.  Use dependent_type_p to check type.
* pt.c (uses_template_parms_p): Use dependent_type_p for a
TYPE_DECL.
(type_dependent_expression_p): Assert we've not been given a
TYPE_DECL.

* g++.dg/parse/typename8.C: New test.
* g++.dg/parse/typename9.C: Likewise.

From-SVN: r107081

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/typename8.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/typename9.C [new file with mode: 0644]

index 27bd947719117665f7163db8ff00acc3c6b372cd..7913b5fca257d2c08ce2748de5257eb3cbb944cb 100644 (file)
@@ -1,3 +1,16 @@
+2005-11-16  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       Backport from mainline:
+       2005-10-12  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/23797
+       * parser.c (cp_parser_functional_cast): Cope when TYPE is not a
+       TYPE_DECL.  Use dependent_type_p to check type.
+       * pt.c (uses_template_parms_p): Use dependent_type_p for a
+       TYPE_DECL.
+       (type_dependent_expression_p): Assert we've not been given a
+       TYPE_DECL.
+
 2005-11-15  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        PR c++/19253
index 70218f92f5ec6d58c7c6a3440a7c62bdcafd8061..c52fa16a300326257a87e1e42f98db52074ad0dd 100644 (file)
@@ -14614,8 +14614,10 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
   cast = build_functional_cast (type, expression_list);
   /* [expr.const]/1: In an integral constant expression "only type
      conversions to integral or enumeration type can be used".  */
-  if (cast != error_mark_node && !type_dependent_expression_p (type) 
-      && !INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (type)))
+  if (TREE_CODE (type) == TYPE_DECL)
+    type = TREE_TYPE (type);
+  if (cast != error_mark_node && !dependent_type_p (type)
+      && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
     {
       if (cp_parser_non_integral_constant_expression 
          (parser, "a call to a constructor"))
index b877fbbe5eef6aa2e141600823ae7a37ff640233..0e4a7b9d3461cb542d25544814448c45c1dc29ab 100644 (file)
@@ -4805,6 +4805,8 @@ uses_template_parms (tree t)
   else if (TREE_CODE (t) == TREE_LIST)
     dependent_p = (uses_template_parms (TREE_VALUE (t))
                   || uses_template_parms (TREE_CHAIN (t)));
+  else if (TREE_CODE (t) == TYPE_DECL)
+    dependent_p = dependent_type_p (TREE_TYPE (t));
   else if (DECL_P (t) 
           || EXPR_P (t) 
           || TREE_CODE (t) == TEMPLATE_PARM_INDEX
@@ -12043,6 +12045,8 @@ type_dependent_expression_p (tree expression)
       abort ();
     }
   
+  my_friendly_assert (TREE_CODE (expression) != TYPE_DECL, 20051116);
   return (dependent_type_p (TREE_TYPE (expression)));
 }
 
index b41dcceda451e396fb3949eb88f1cb0cbb8d6c7b..dae4f0f59a04cdf5e1f57175806e105af0a69e64 100644 (file)
@@ -1,3 +1,10 @@
+2005-11-16  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
+
+       PR c++/23797
+       Backport from mainline:
+       * g++.dg/parse/typename8.C: New test.
+       * g++.dg/parse/typename9.C: Likewise.
+
 2005-11-15  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>
 
        Backport from mainline:
diff --git a/gcc/testsuite/g++.dg/parse/typename8.C b/gcc/testsuite/g++.dg/parse/typename8.C
new file mode 100644 (file)
index 0000000..e8e7627
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright (C) 2005 Free Software Foundation, Inc.
+// Contributed by Nathan Sidwell 12 Oct 2005 <nathan@codesourcery.com>
+
+// PR 23797:ICE
+// Origin:  Volker Reichelt <reichelt@gcc.gnu.org>
+
+// { dg-options "-fpermissive -w" }
+
+struct A { typedef int X; };
+
+int i = typename A::X();
diff --git a/gcc/testsuite/g++.dg/parse/typename9.C b/gcc/testsuite/g++.dg/parse/typename9.C
new file mode 100644 (file)
index 0000000..aa72cd6
--- /dev/null
@@ -0,0 +1,3 @@
+struct A { typedef int X; };
+
+int i = typename A::X(); // { dg-error "typename" }