re PR c++/15227 (Trouble with invalid function definition)
authorMark Mitchell <mark@codesourcery.com>
Thu, 10 Jun 2004 14:26:23 +0000 (14:26 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Thu, 10 Jun 2004 14:26:23 +0000 (14:26 +0000)
PR c++/15227
* parser.c (cp_parser_direct_declarator): Robustify.

PR c++/15877
* pt.c (tsubst_copy): Use decl_constant_value on enumeration
constants in non-dependent contexts.

PR c++/14211
PR c++/15076
* typeck.c (build_static_cast): Wrap casts in NON_LVALUE_EXPR when
necessary.

PR c++/14211
* g++.dg/conversion/const1.C: New test.

PR c++/15076
* g++.dg/conversion/reinterpret1.C: New test.

PR c++/15877
* g++.dg/template/enum2.C: New test.

PR c++/15227
* g++.dg/template/error13.C: New test.

From-SVN: r82917

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/pt.c
gcc/cp/typeck.c
gcc/testsuite/g++.dg/conversion/const1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/conversion/reinterpret1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/enum2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/error13.C [new file with mode: 0644]

index c080fb3aba7c9b2a22d27ec59a573eda39488ee6..5f49e4ba24fc21fb0f141482cffeb35424649b8c 100644 (file)
@@ -1,3 +1,17 @@
+2004-06-10  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/15227
+       * parser.c (cp_parser_direct_declarator): Robustify.
+
+       PR c++/15877
+       * pt.c (tsubst_copy): Use decl_constant_value on enumeration
+       constants in non-dependent contexts.
+
+       PR c++/14211
+       PR c++/15076
+       * typeck.c (build_static_cast): Wrap casts in NON_LVALUE_EXPR when
+       necessary.
+
 2004-06-10  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/14791
index a90dabd0c8ca55d209ee7cb7ad3fb7b3a9767691..17242ba3457107eae5538b4b1b451bd20ba3b4bb 100644 (file)
@@ -10726,8 +10726,10 @@ cp_parser_direct_declarator (cp_parser* parser,
                  type = resolve_typename_type (scope,
                                                 /*only_current_p=*/false);
                  /* If that failed, the declarator is invalid.  */
-                 if (type != error_mark_node)
-                   scope = type;
+                 if (type == error_mark_node)
+                   error ("`%T::%D' is not a type",
+                          TYPE_CONTEXT (scope),
+                          TYPE_IDENTIFIER (scope));
                  /* Build a new DECLARATOR.  */
                  declarator = build_nt (SCOPE_REF,
                                         scope,
index 8e29e244f71afdc10a69562ed40d40e5ebe78193..fd75f78cd9a5c681cf48d6aa869445b23d553059 100644 (file)
@@ -7421,7 +7421,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
          return t;
        /* If ARGS is NULL, then T is known to be non-dependent.  */
        if (args == NULL_TREE)
-         return t;
+         return decl_constant_value (t);
 
        /* Unfortunately, we cannot just call lookup_name here.
           Consider:
index 5e5dcc4a2ae552bce76977902a6c0fb97395581c..bcdd316131ba4ae3231f1879eb788e8e4ae7dbef 100644 (file)
@@ -4535,7 +4535,17 @@ build_static_cast (tree type, tree expr)
      t.  */
   result = perform_direct_initialization_if_possible (type, expr);
   if (result)
-    return convert_from_reference (result);
+    {
+      result = convert_from_reference (result);
+      /* [expr.static.cast]
+
+         If T is a reference type, the result is an lvalue; otherwise,
+        the result is an rvalue.  */
+      if (TREE_CODE (type) != REFERENCE_TYPE
+         && real_lvalue_p (result))
+       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
+      return result;
+    }
   
   /* [expr.static.cast]
 
diff --git a/gcc/testsuite/g++.dg/conversion/const1.C b/gcc/testsuite/g++.dg/conversion/const1.C
new file mode 100644 (file)
index 0000000..5e43bc0
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/14211
+
+void f(char *str) {
+  char *& m = const_cast<char *>(str); // { dg-error "" }
+}
diff --git a/gcc/testsuite/g++.dg/conversion/reinterpret1.C b/gcc/testsuite/g++.dg/conversion/reinterpret1.C
new file mode 100644 (file)
index 0000000..72ec750
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/15076
+
+struct Y { Y(int &); }; // { dg-error "" }
+
+int v;
+Y y1(reinterpret_cast<int>(v));  // { dg-error "" }
diff --git a/gcc/testsuite/g++.dg/template/enum2.C b/gcc/testsuite/g++.dg/template/enum2.C
new file mode 100644 (file)
index 0000000..7a6c207
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/15877
+
+template <int n> struct T1 { enum { N = 3 }; };
+template <int n> struct T2 { enum { N = n, N1 = T1<N>::N }; }; 
diff --git a/gcc/testsuite/g++.dg/template/error13.C b/gcc/testsuite/g++.dg/template/error13.C
new file mode 100644 (file)
index 0000000..13d8794
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/15227
+
+template<typename> struct A {};
+
+template<typename T> void A<T>::B::foo() {} // { dg-error "" }