OSDN Git Service

PR c++/9354
authormmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 23 Jan 2003 06:05:20 +0000 (06:05 +0000)
committermmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 23 Jan 2003 06:05:20 +0000 (06:05 +0000)
* init.c (build_new): Set the type of the new-expression, even
when processing_templte_decl.

PR c++/9216
* parser.c (cp_parser_primary_expression): Improve error message
for templates used in an expression context.

PR c++/8696
* parser.c (cp_parser_decl_specifier_seq): Commit to tentative
parse when encountering "typedef".

PR c++/9354
* g++.dg/parse/new1.C: New test.

PR c++/9216
* g++.dg/parse/template2.C: New test.

PR c++/9354
* g++.dg/parse/typedef2.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@61643 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/new1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/template2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/parse/typedef2.C [new file with mode: 0644]

index 3671119..be97c50 100644 (file)
@@ -1,3 +1,17 @@
+2003-01-22  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/9354
+       * init.c (build_new): Set the type of the new-expression, even
+       when processing_templte_decl.
+
+       PR c++/9216
+       * parser.c (cp_parser_primary_expression): Improve error message
+       for templates used in an expression context.
+
+       PR c++/8696
+       * parser.c (cp_parser_decl_specifier_seq): Commit to tentative
+       parse when encountering "typedef".
+
 2003-01-22  Nathanael Nerode  <neroden@gcc.gnu.org>
 
        * class.c, parser.c: ANSIfy function definitions and declarations.
index c822516..493f9b8 100644 (file)
@@ -2024,7 +2024,8 @@ build_new (placement, decl, init, use_global_new)
       else
        t = type;
        
-      rval = build_min_nt (NEW_EXPR, placement, t, init);
+      rval = build_min (NEW_EXPR, build_pointer_type (type), 
+                       placement, t, init);
       NEW_EXPR_USE_GLOBAL (rval) = use_global_new;
       return rval;
     }
index 8e5dc33..4d809b8 100644 (file)
@@ -2562,10 +2562,14 @@ cp_parser_primary_expression (cp_parser *parser,
 
        /* If we didn't find anything, or what we found was a type,
           then this wasn't really an id-expression.  */
-       if (TREE_CODE (decl) == TYPE_DECL
-           || TREE_CODE (decl) == NAMESPACE_DECL
-           || (TREE_CODE (decl) == TEMPLATE_DECL
-               && !DECL_FUNCTION_TEMPLATE_P (decl)))
+       if (TREE_CODE (decl) == TEMPLATE_DECL
+           && !DECL_FUNCTION_TEMPLATE_P (decl))
+         {
+           cp_parser_error (parser, "missing template arguments");
+           return error_mark_node;
+         }
+       else if (TREE_CODE (decl) == TYPE_DECL
+                || TREE_CODE (decl) == NAMESPACE_DECL)
          {
            cp_parser_error (parser, 
                             "expected primary-expression");
@@ -6582,6 +6586,9 @@ cp_parser_decl_specifier_seq (cp_parser* parser,
          cp_lexer_consume_token (parser->lexer);
          /* A constructor declarator cannot appear in a typedef.  */
          constructor_possible_p = false;
+         /* The "typedef" keyword can only occur in a declaration; we
+            may as well commit at this point.  */
+         cp_parser_commit_to_tentative_parse (parser);
          break;
 
          /* storage-class-specifier:
index fb0a778..5dcd1d1 100644 (file)
@@ -1,5 +1,14 @@
 2003-01-22  Mark Mitchell  <mark@codesourcery.com>
 
+       PR c++/9354
+       * g++.dg/parse/new1.C: New test.
+
+       PR c++/9216
+       * g++.dg/parse/template2.C: New test.
+
+       PR c++/9354
+       * g++.dg/parse/typedef2.C: New test.
+
        PR c++/9328
        * g++.dg/ext/typeof3.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/parse/new1.C b/gcc/testsuite/g++.dg/parse/new1.C
new file mode 100644 (file)
index 0000000..31dad77
--- /dev/null
@@ -0,0 +1,7 @@
+struct T;
+T* manage(T* t);
+template <class Obj> struct ObjectSlot0_ {
+  void create() {
+    void* tmp = manage(new T());
+  }
+};
diff --git a/gcc/testsuite/g++.dg/parse/template2.C b/gcc/testsuite/g++.dg/parse/template2.C
new file mode 100644 (file)
index 0000000..6689c8b
--- /dev/null
@@ -0,0 +1,7 @@
+namespace N {
+  template < typename T > class C : T {};
+}
+
+int main() {
+  N::C(); // { dg-error "template" }
+}
diff --git a/gcc/testsuite/g++.dg/parse/typedef2.C b/gcc/testsuite/g++.dg/parse/typedef2.C
new file mode 100644 (file)
index 0000000..3ae347d
--- /dev/null
@@ -0,0 +1,3 @@
+template <typename T> struct B { typedef typename T::X X; };
+template <typename T> struct A { typedef B<T>::X::Y Z; }; // { dg-error "" }