aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2005-02-23 05:30:48 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2005-02-23 05:30:48 +0000
commit744b12b65f6923a713593f404f97384c6093dd94 (patch)
treeb003a007ec3edf4d8323134ca4e5d3a88c20f95d
parent90c1d75a9bb8e25aa963da02f9c91f5f40143be1 (diff)
downloadgcc-744b12b65f6923a713593f404f97384c6093dd94.zip
gcc-744b12b65f6923a713593f404f97384c6093dd94.tar.gz
gcc-744b12b65f6923a713593f404f97384c6093dd94.tar.bz2
re PR c++/19991 (Enum not accepted in array-size)
PR c++/19991 * init.c (integral_constant_value): Iterate if the value of a decl is itself a constant. PR c++/20152 * parser.c (cp_parser_class_head): Check for redefintions here. * semantics.c (begin_class_definition): Not here. PR c++/20153 * decl2.c (build_anon_union_vars): Add type parameter. (finish_anon_union): Pass it. PR c++/20148 * error.c (dump_expr): Do not print the body of a BIND_EXPR. Handle STATEMENT_LIST. PR c++/19991 * g++.dg/parse/constant7.C: New test. PR c++/20152 * g++.dg/parse/error27.C: New test. * g++.dg/template/qualttp15.C: Adjust error markers. * g++.old-deja/g++.other/struct1.C: Likewise. PR c++/20153 * g++.dg/template/error17.C: New test. PR c++/20148 * g++.dg/parser/error26.C: New test. From-SVN: r95438
-rw-r--r--gcc/cp/ChangeLog16
-rw-r--r--gcc/cp/decl2.c14
-rw-r--r--gcc/cp/error.c8
-rw-r--r--gcc/cp/init.c22
-rw-r--r--gcc/cp/parser.c12
-rw-r--r--gcc/cp/semantics.c9
-rw-r--r--gcc/testsuite/ChangeLog16
-rw-r--r--gcc/testsuite/g++.dg/parse/constant7.C9
-rw-r--r--gcc/testsuite/g++.dg/parse/error26.C12
-rw-r--r--gcc/testsuite/g++.dg/parse/error27.C7
-rw-r--r--gcc/testsuite/g++.dg/template/error17.C8
-rw-r--r--gcc/testsuite/g++.dg/template/qualttp15.C4
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/struct1.C20
13 files changed, 109 insertions, 48 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 4abda48..611100c 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,21 @@
2005-02-22 Mark Mitchell <mark@codesourcery.com>
+ PR c++/19991
+ * init.c (integral_constant_value): Iterate if the value of a decl
+ is itself a constant.
+
+ PR c++/20152
+ * parser.c (cp_parser_class_head): Check for redefintions here.
+ * semantics.c (begin_class_definition): Not here.
+
+ PR c++/20153
+ * decl2.c (build_anon_union_vars): Add type parameter.
+ (finish_anon_union): Pass it.
+
+ PR c++/20148
+ * error.c (dump_expr): Do not print the body of a BIND_EXPR.
+ Handle STATEMENT_LIST.
+
PR c++/19883
* parser.c (cp_parser_direct_declarator): Always complain about
non-constant array bounds when in a function scope.
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 8243cb1..7ed490e 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -65,7 +65,6 @@ typedef struct priority_info_s {
static void mark_vtable_entries (tree);
static bool maybe_emit_vtables (tree);
-static tree build_anon_union_vars (tree);
static bool acceptable_java_type (tree);
static tree start_objects (int, int);
static void finish_objects (int, int, tree);
@@ -1072,14 +1071,13 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags)
SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl), TREE_TYPE (*decl));
}
-/* Walks through the namespace- or function-scope anonymous union OBJECT,
- building appropriate ALIAS_DECLs. Returns one of the fields for use in
- the mangled name. */
+/* Walks through the namespace- or function-scope anonymous union
+ OBJECT, with the indicated TYPE, building appropriate ALIAS_DECLs.
+ Returns one of the fields for use in the mangled name. */
static tree
-build_anon_union_vars (tree object)
+build_anon_union_vars (tree type, tree object)
{
- tree type = TREE_TYPE (object);
tree main_decl = NULL_TREE;
tree field;
@@ -1127,7 +1125,7 @@ build_anon_union_vars (tree object)
decl = pushdecl (decl);
}
else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
- decl = build_anon_union_vars (ref);
+ decl = build_anon_union_vars (TREE_TYPE (field), ref);
else
decl = 0;
@@ -1167,7 +1165,7 @@ finish_anon_union (tree anon_union_decl)
return;
}
- main_decl = build_anon_union_vars (anon_union_decl);
+ main_decl = build_anon_union_vars (type, anon_union_decl);
if (main_decl == NULL_TREE)
{
warning ("anonymous union with no members");
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 86ea7aa..888a4e8 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -1815,18 +1815,14 @@ dump_expr (tree t, int flags)
dump_decl (t, flags);
break;
+ case BIND_EXPR:
case STMT_EXPR:
+ case STATEMENT_LIST:
/* We don't yet have a way of dumping statements in a
human-readable format. */
pp_string (cxx_pp, "({...})");
break;
- case BIND_EXPR:
- pp_cxx_left_brace (cxx_pp);
- dump_expr (TREE_OPERAND (t, 1), flags & ~TFF_EXPR_IN_PARENS);
- pp_cxx_right_brace (cxx_pp);
- break;
-
case LOOP_EXPR:
pp_string (cxx_pp, "while (1) { ");
dump_expr (TREE_OPERAND (t, 0), flags & ~TFF_EXPR_IN_PARENS);
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 4ad5e62..1a81961 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1570,17 +1570,17 @@ build_offset_ref (tree type, tree name, bool address_p)
tree
integral_constant_value (tree decl)
{
- if ((TREE_CODE (decl) == CONST_DECL
- || (TREE_CODE (decl) == VAR_DECL
- /* And so are variables with a 'const' type -- unless they
- are also 'volatile'. */
- && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))
- && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)))
- && DECL_INITIAL (decl)
- && DECL_INITIAL (decl) != error_mark_node
- && TREE_TYPE (DECL_INITIAL (decl))
- && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
- return DECL_INITIAL (decl);
+ while ((TREE_CODE (decl) == CONST_DECL
+ || (TREE_CODE (decl) == VAR_DECL
+ /* And so are variables with a 'const' type -- unless they
+ are also 'volatile'. */
+ && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl))
+ && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl)))
+ && DECL_INITIAL (decl)
+ && DECL_INITIAL (decl) != error_mark_node
+ && TREE_TYPE (DECL_INITIAL (decl))
+ && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
+ decl = DECL_INITIAL (decl);
return decl;
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index b52ba95..765991f 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -12842,9 +12842,17 @@ cp_parser_class_head (cp_parser* parser,
CLASSTYPE_DECLARED_CLASS (type) = (class_key == class_type);
cp_parser_check_class_key (class_key, type);
+ /* If this type was already complete, and we see another definition,
+ that's an error. */
+ if (type != error_mark_node && COMPLETE_TYPE_P (type))
+ {
+ error ("redefinition of %q#T", type);
+ cp_error_at ("previous definition of %q#T", type);
+ type = error_mark_node;
+ }
+
/* We will have entered the scope containing the class; the names of
- base classes should be looked up in that context. For example,
- given:
+ base classes should be looked up in that context. For example:
struct A { struct B {}; struct C; };
struct A::C : B {};
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 4ff333b..2daff6f 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2125,15 +2125,6 @@ begin_class_definition (tree t)
pushtag (make_anon_name (), t, 0);
}
- /* If this type was already complete, and we see another definition,
- that's an error. */
- if (COMPLETE_TYPE_P (t))
- {
- error ("redefinition of %q#T", t);
- cp_error_at ("previous definition of %q#T", t);
- return error_mark_node;
- }
-
/* Update the location of the decl. */
DECL_SOURCE_LOCATION (TYPE_NAME (t)) = input_location;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 530d9a3..c72149c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,19 @@
+2005-02-22 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/19991
+ * g++.dg/parse/constant7.C: New test.
+
+ PR c++/20152
+ * g++.dg/parse/error27.C: New test.
+ * g++.dg/template/qualttp15.C: Adjust error markers.
+ * g++.old-deja/g++.other/struct1.C: Likewise.
+
+ PR c++/20153
+ * g++.dg/template/error17.C: New test.
+
+ PR c++/20148
+ * g++.dg/parser/error26.C: New test.
+
2005-02-22 Diego Novillo <dnovillo@redhat.com>
PR tree-optimization/20100
diff --git a/gcc/testsuite/g++.dg/parse/constant7.C b/gcc/testsuite/g++.dg/parse/constant7.C
new file mode 100644
index 0000000..c54ad55
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/constant7.C
@@ -0,0 +1,9 @@
+// PR c++/19991
+
+enum { e = 1 };
+
+template<typename> struct A
+{
+ static const int i = e;
+ char a[i];
+};
diff --git a/gcc/testsuite/g++.dg/parse/error26.C b/gcc/testsuite/g++.dg/parse/error26.C
new file mode 100644
index 0000000..6e2b897
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error26.C
@@ -0,0 +1,12 @@
+// PR c++/20148
+// { dg-options "" }
+
+void foo()
+{
+ if (({int c[2];})) ; // { dg-error "\{\.\.\.\}" }
+}
+
+void bar()
+{
+ if (({})); // { dg-error "\{\.\.\.\}" }
+}
diff --git a/gcc/testsuite/g++.dg/parse/error27.C b/gcc/testsuite/g++.dg/parse/error27.C
new file mode 100644
index 0000000..f52d3ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/error27.C
@@ -0,0 +1,7 @@
+// PR c++/20152
+
+struct KrSelectionMode { virtual void init() = 0; }; // { dg-error "previous definition" }
+struct KrKDESelectionMode : public KrSelectionMode { void init() { } }; // { dg-error "previous definition" }
+struct KrSelectionMode { virtual void init() = 0; }; // { dg-error "" }
+struct KrKDESelectionMode : public KrSelectionMode { void init() { } }; // { dg-error "" }
+KrKDESelectionMode krKDESelectionMode;
diff --git a/gcc/testsuite/g++.dg/template/error17.C b/gcc/testsuite/g++.dg/template/error17.C
new file mode 100644
index 0000000..24b3644
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/error17.C
@@ -0,0 +1,8 @@
+// PR c++/20153
+
+template <typename T>
+void
+foo()
+{
+ union { struct { }; }; // { dg-error "" }
+}
diff --git a/gcc/testsuite/g++.dg/template/qualttp15.C b/gcc/testsuite/g++.dg/template/qualttp15.C
index 1b1f3bb..0f97c32 100644
--- a/gcc/testsuite/g++.dg/template/qualttp15.C
+++ b/gcc/testsuite/g++.dg/template/qualttp15.C
@@ -17,8 +17,8 @@ template <class T> struct X<T::template B>
T z;
};
-template <class T> struct X<T::template B>
-{ // { dg-error "redefinition" }
+template <class T> struct X<T::template B> // { dg-error "redefinition" }
+{
T z;
};
diff --git a/gcc/testsuite/g++.old-deja/g++.other/struct1.C b/gcc/testsuite/g++.old-deja/g++.other/struct1.C
index f4fa322..b1f943f 100644
--- a/gcc/testsuite/g++.old-deja/g++.other/struct1.C
+++ b/gcc/testsuite/g++.old-deja/g++.other/struct1.C
@@ -9,34 +9,34 @@
class Y
{ // { dg-error "" } previous definition
};
-class Y
-{ // { dg-error "" } redefinition
+class Y // { dg-error "" } redefinition
+{
};
template<class T> class X
{ // { dg-error "" } previous definition
};
-template<class T> class X
-{ // { dg-error "" } redefinition
+template<class T> class X // { dg-error "" } redefinition
+{
};
template<class T> class X<T *>
{ // { dg-error "" } previous definition
};
-template<class T> class X<T *>
-{ // { dg-error "" } redefinition
+template<class T> class X<T *> // { dg-error "" } redefinition
+{
};
template<> class X<int>
{ // { dg-error "" } previous definition
};
-template<> class X<int>
-{ // { dg-error "" } redefinition
+template<> class X<int> // { dg-error "" } redefinition
+{
};
template<> class X<int *>
{ // { dg-error "" } previous definition
};
-template<> class X<int *>
-{ // { dg-error "" } redefinition
+template<> class X<int *> // { dg-error "" } redefinition
+{
};