re PR c++/18389 (ICE on struct declaration in for statement)
authorMark Mitchell <mark@codesourcery.com>
Fri, 12 Nov 2004 21:47:13 +0000 (21:47 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Fri, 12 Nov 2004 21:47:13 +0000 (21:47 +0000)
PR c++/18389
* decl.c (start_decl): Make sure to set *pop_scope_p.  Return
error_mark_node to indicate errors.

PR c++/18429
* parser.c (cp_parser_direct_declarator): Disallow non-constant
array bounds when not inside a function.

PR c++/18436
* pt.c (tsubst_copy_and_build): Do not do Koenig lookup when an
unqualified name resolves to a member function.

PR c++/18407
* pt.c (tsubst_copy_and_build): Handle qualified names used from a
derived class correctly.

* decl2.c (import_export_decl): Fix typo in comment.
* tree.c (pod_type_p): Likewise.

PR c++/18389
* g++.dg/parse/cond1.C: New test.

PR c++/18429
* g++.dg/template/array9.C: New test.
* g++.dg/ext/vla1.C: Adjust error messages.
* g++.dg/ext/vlm1.C: Likewise.
* g++.dg/template/crash2.C: Likewise.

PR c++/18436
* g++.dg/template/call3.C: New test.

PR c++/18407
* g++.dg/template/ptrmem11.C: New test.

From-SVN: r90545

14 files changed:
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/decl2.c
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/vla1.C
gcc/testsuite/g++.dg/ext/vlm1.C
gcc/testsuite/g++.dg/parse/cond1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/array9.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/call3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/crash2.C
gcc/testsuite/g++.dg/template/ptrmem11.C [new file with mode: 0644]

index 1b34b951994d2daf3441a1abb5712e7cd1a22ecf..fe51d5b5b5e497fce815d340593be9aaa176d8da 100644 (file)
@@ -1,3 +1,24 @@
+2004-11-12  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/18389
+       * decl.c (start_decl): Make sure to set *pop_scope_p.  Return
+       error_mark_node to indicate errors.
+
+       PR c++/18429
+       * parser.c (cp_parser_direct_declarator): Disallow non-constant
+       array bounds when not inside a function.
+
+       PR c++/18436
+       * pt.c (tsubst_copy_and_build): Do not do Koenig lookup when an
+       unqualified name resolves to a member function.
+
+       PR c++/18407
+       * pt.c (tsubst_copy_and_build): Handle qualified names used from a
+       derived class correctly.
+       
+       * decl2.c (import_export_decl): Fix typo in comment.
+       * tree.c (pod_type_p): Likewise.
+
 2004-11-10  Andrew Pinski  <pinskia@physics.uc.edu>
 
        * typeck.c (cxx_mark_addressable): Add braces around the first if.
index a6961215396730e9ffaf7c0755d168d07426d64e..472b1f92e87292db503ba56597fe91d98ee460e7 100644 (file)
@@ -3670,6 +3670,8 @@ start_decl (const cp_declarator *declarator,
   tree type, tem;
   tree context;
 
+  *pop_scope_p = false;
   /* This should only be done once on the top most decl.  */
   if (have_extern_spec)
     {
@@ -3690,19 +3692,17 @@ start_decl (const cp_declarator *declarator,
   deprecated_state = DEPRECATED_NORMAL;
 
   if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE)
-    return NULL_TREE;
+    return error_mark_node;
 
   type = TREE_TYPE (decl);
 
   if (type == error_mark_node)
-    return NULL_TREE;
+    return error_mark_node;
 
   context = DECL_CONTEXT (decl);
 
   if (context)
     *pop_scope_p = push_scope (context);
-  else
-    *pop_scope_p = false;
   
   /* We are only interested in class contexts, later.  */
   if (context && TREE_CODE (context) == NAMESPACE_DECL)
index 03c51e779075934ad79eedb4b1f5840c7db54380..d8987e27be0ce3f12668de03342a81f8a3e34668 100644 (file)
@@ -1743,7 +1743,7 @@ import_export_decl (tree decl)
      vague linkage, maybe_commonize_var is used.
 
      Therefore, the only declarations that should be provided to this
-     function are those with external linkage that:
+     function are those with external linkage that are:
 
      * implicit instantiations of function templates
 
index ef02ba9f514fc5c9436a23f805571c79bc914240..265abdb81e42e60b38ce6b38d07d739a3496387c 100644 (file)
@@ -10960,6 +10960,11 @@ cp_parser_direct_declarator (cp_parser* parser,
                                                 &non_constant_p);
              if (!non_constant_p)
                bounds = fold_non_dependent_expr (bounds);
+             else if (!at_function_scope_p ())
+               {
+                 error ("array bound is not an integer constant");
+                 bounds = error_mark_node;
+               }
            }
          else
            bounds = NULL_TREE;
index 28ae8f375b3ca5db63f5355a53dbb81b421ae486..54c997951edea45cdf569147075868d66c762612 100644 (file)
@@ -8543,7 +8543,11 @@ tsubst_copy_and_build (tree t,
           lookup finds a non-function, in accordance with the
           expected resolution of DR 218.  */
        if (koenig_p
-           && (is_overloaded_fn (function)
+           && ((is_overloaded_fn (function)
+                /* If lookup found a member function, the Koenig lookup is
+                   not appropriate, even if an unqualified-name was used
+                   to denote the function.  */
+                && !DECL_FUNCTION_MEMBER_P (get_first_fn (function)))
                || TREE_CODE (function) == IDENTIFIER_NODE))
          function = perform_koenig_lookup (function, call_args);
 
@@ -8659,9 +8663,14 @@ tsubst_copy_and_build (tree t,
                                            /*is_type_p=*/false,
                                            /*complain=*/false);
            if (BASELINK_P (member))
-             BASELINK_FUNCTIONS (member) 
-               = build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member),
-                           args);
+             {
+               BASELINK_FUNCTIONS (member) 
+                 = build_nt (TEMPLATE_ID_EXPR, BASELINK_FUNCTIONS (member),
+                             args);
+               member = (adjust_result_of_qualified_name_lookup 
+                         (member, BINFO_TYPE (BASELINK_BINFO (member)), 
+                          TREE_TYPE (object)));
+             }
            else
              {
                qualified_name_lookup_error (TREE_TYPE (object), tmpl,
index afe42e23730cb8cf8c2dc17333b12d671d6d72cc..82aebe49550e887004b66b5e081e45da9da55848 100644 (file)
@@ -1716,7 +1716,7 @@ pod_type_p (tree t)
     return 1; /* pointer to member */
 
   if (TREE_CODE (t) == VECTOR_TYPE)
-    return 1; /* vectors are (small) arrays if scalars */
+    return 1; /* vectors are (small) arrays of scalars */
 
   if (! CLASS_TYPE_P (t))
     return 0; /* other non-class type (reference or function) */
index 853cd4a6a4821d463e3242e01f5d75480d3f9a77..10bac622f8026b22b021eb5bc40c576892b16d7d 100644 (file)
@@ -1,3 +1,20 @@
+2004-11-12  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/18389
+       * g++.dg/parse/cond1.C: New test.
+
+       PR c++/18429
+       * g++.dg/template/array9.C: New test.
+       * g++.dg/ext/vla1.C: Adjust error messages.
+       * g++.dg/ext/vlm1.C: Likewise.
+       * g++.dg/template/crash2.C: Likewise.
+
+       PR c++/18436
+       * g++.dg/template/call3.C: New test.
+
+       PR c++/18407
+       * g++.dg/template/ptrmem11.C: New test.
+
 2004-11-12  Andrew Pinski  <pinskia@physics.uc.edu>
 
        PR other/14264
index bac5aaca1a50cb44fa1eeabd42d7ea33bb9396c8..f2238c2fdd467cdd1cd84a134a7e86f120641e0c 100644 (file)
@@ -19,7 +19,7 @@ class B { B (int); };
 B::B (int i)
 {
   struct S {
-    int ar[1][i];  // { dg-error "variable-size|variably modified" }
+    int ar[1][i];  // { dg-error "array" }
   } s;
 
   s.ar[0][0] = 0;  // { dg-error "no member" }
index 13f6702771064704d2b25b6bb17c50d20b4c7db0..9cb6c38be1523c434c4adcf631844a1e88f8aa47 100644 (file)
@@ -4,7 +4,7 @@ template <class T> struct A {};
  
 struct B {
   static const int s;
-  A<int[s]> a; // { dg-error "variably modified|no type|trying to instantiate" }
+  A<int[s]> a; // { dg-error "array|template" }
 };
  
 const int B::s=16;
diff --git a/gcc/testsuite/g++.dg/parse/cond1.C b/gcc/testsuite/g++.dg/parse/cond1.C
new file mode 100644 (file)
index 0000000..6994773
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/18389
+
+void foo()
+{
+  for (; struct A {}; ); // { dg-error "" }
+}
diff --git a/gcc/testsuite/g++.dg/template/array9.C b/gcc/testsuite/g++.dg/template/array9.C
new file mode 100644 (file)
index 0000000..f3e8335
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/18429
+
+int subtrees = 4;
+template< class T >
+struct Tree {
+  Tree* L[subtrees]; // { dg-error "" }
+  Tree* R[subtrees]; // { dg-error "" }
+  ~Tree()
+  {
+    delete [] L[0]; // { dg-error "" }
+    delete [] R[0]; // { dg-error "" }
+  }
+};
+
+void f()
+{
+  Tree<int> t;
+}
diff --git a/gcc/testsuite/g++.dg/template/call3.C b/gcc/testsuite/g++.dg/template/call3.C
new file mode 100644 (file)
index 0000000..1dd2b51
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/18436
+
+void foo(int);
+
+struct A
+{
+  static void foo(A);
+};
+
+template <typename T> struct B : T
+{
+  B() { foo(T()); }
+};
+
+B<A> b;
index a02787a46fa0b8db20a7187677bb27b2c0fbf263..8bf7b450df256673e4b1217defe3b8da845acd1a 100644 (file)
@@ -5,7 +5,7 @@ class A
 {
 public:
   static const EnumType size = max; // { dg-error "" }
-  int table[size];
+  int table[size]; // { dg-error "" }
 };
 template <class EnumType>
 const EnumType A<EnumType>::size;
diff --git a/gcc/testsuite/g++.dg/template/ptrmem11.C b/gcc/testsuite/g++.dg/template/ptrmem11.C
new file mode 100644 (file)
index 0000000..da2ce49
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/18407
+
+template <typename Class>
+struct the_base{
+  template <void (Class::*Fn)()> void foo() { }
+};
+
+template <typename T>
+struct derivedT: the_base<derivedT<T> > {
+  typedef the_base<derivedT<T> > parent;
+  void ice(){
+    this->parent::template foo< &derivedT<T>::ice>();
+  }
+};
+
+int main() {
+  derivedT<int> dT;
+  dT.ice();
+}