+2004-11-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/17473
+ * name-lookup.c (supplement_binding): Do not allow typedefs to be
+ redefined in class scope.
+
+ PR c++/18285
+ * parser.c (cp_parser_set_decl_type_spec): Do not try to allow
+ redefinitions of builtin types other that "bool" or "wchar_t".
+
2004-11-24 Steven Bosscher <stevenb@suse.de>
* decl.c (cxx_init_decl_processing): Don't clear
else if (TREE_CODE (bval) == TYPE_DECL
&& TREE_CODE (decl) == TYPE_DECL
&& DECL_NAME (decl) == DECL_NAME (bval)
+ && binding->scope->kind != sk_class
&& (same_type_p (TREE_TYPE (decl), TREE_TYPE (bval))
/* If either type involves template parameters, we must
wait until instantiation. */
|| uses_template_parms (TREE_TYPE (decl))
|| uses_template_parms (TREE_TYPE (bval))))
/* We have two typedef-names, both naming the same type to have
- the same name. This is OK because of:
+ the same name. In general, this is OK because of:
[dcl.typedef]
In a given scope, a typedef specifier can be used to redefine
the name of any type declared in that scope to refer to the
- type to which it already refers. */
+ type to which it already refers.
+
+ However, in class scopes, this rule does not apply due to the
+ stricter language in [class.mem] prohibiting redeclarations of
+ members. */
ok = false;
/* There can be two block-scope declarations of the same variable,
so long as they are `extern' declarations. However, there cannot
{
decl_specs->any_specifiers_p = true;
- /* If the user tries to redeclare a built-in type (with, for example,
- in "typedef int wchar_t;") we remember that this is what
+ /* If the user tries to redeclare bool or wchar_t (with, for
+ example, in "typedef int wchar_t;") we remember that this is what
happened. In system headers, we ignore these declarations so
that G++ can work with system headers that are not C++-safe. */
if (decl_specs->specs[(int) ds_typedef]
&& !user_defined_p
+ && (type_spec == boolean_type_node
+ || type_spec == wchar_type_node)
&& (decl_specs->type
|| decl_specs->specs[(int) ds_long]
|| decl_specs->specs[(int) ds_short]
+2004-11-24 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/17473
+ * g++.dg/tc1/dr56.C: Remove.
+ * g++.dg/template/typedef1.C: Add dg-error markers.
+ * g++.old-deja/g++.other/typedef7.C: Likewise.
+
+ PR c++/18285
+ * g++.dg/parse/typedef7.C: New test.
+
2004-11-24 Richard Sandiford <rsandifo@redhat.com>
* gcc.c-torture/execute/20041124-1.c: New test.
--- /dev/null
+// PR c++/18285
+typedef void int char void double X; // { dg-error "" }
+++ /dev/null
-// { dg-do compile }
-// Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
-// DR56: Redeclaring typedefs within classes
-
-class X {
- typedef int I;
- typedef int I; // { dg-error "" "Cannot redeclare a typedef in a class scope" { xfail *-*-* } }
-};
-
-// In non-class scope, they are allowed.
-typedef int A;
-typedef int A;
template <typename T> struct B
{
- typedef int xxx;
- typedef T xxx;
- typedef typename A<T>::type xxx;
- typedef A<int>::type xxx;
+ typedef int xxx; // { dg-error "" }
+ typedef T xxx; // { dg-error "" }
+ typedef typename A<T>::type xxx; // { dg-error "" }
+ typedef A<int>::type xxx; // { dg-error "" }
};
B<int> good;
typedef int I;
typedef int I;
+// DR56 makes clear that duplicate typedefs in class scopes are
+// invalid.
+
struct A {
- typedef int I;
- typedef int I;
+ typedef int I; // { dg-error "" }
+ typedef int I; // { dg-error "" }
};
template <class T>
struct S {
- typedef int I;
- typedef int I;
+ typedef int I; // { dg-error "" }
+ typedef int I; // { dg-error "" }
};