aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>2002-07-02 03:14:24 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2002-07-02 03:14:24 +0000
commitb20631537e555fa49f8e4982774e04835f7f6156 (patch)
tree0ed54dda170314bc73e15543fc80a4b9cb07165d
parent719d7fd750b17abe715b9af08ccb7979008e5949 (diff)
downloadgcc-b20631537e555fa49f8e4982774e04835f7f6156.zip
gcc-b20631537e555fa49f8e4982774e04835f7f6156.tar.gz
gcc-b20631537e555fa49f8e4982774e04835f7f6156.tar.bz2
re PR c++/7112 (Regression: ICE on C++ code involving templates and sizeof)
PR c++/7112 * g++.dg/template/sizeof1.C: New test. PR c++/7112 * mangle.c (write_expression): Add mangling for sizeof when applied to a type. * operators.def: Remove stale comment. * cp-demangle.c (demangle_operator_name): Add type_arg parameter. Set it for the "st" operator. (demangle_expression): Handle expressions with types as arguments. From-SVN: r55168
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/mangle.c7
-rw-r--r--gcc/cp/operators.def6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/template/sizeof1.C26
-rw-r--r--libiberty/ChangeLog6
-rw-r--r--libiberty/cp-demangle.c39
7 files changed, 74 insertions, 22 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 68fa155..d65a58e 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2002-07-01 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/7112
+ * mangle.c (write_expression): Add mangling for sizeof when
+ applied to a type.
+ * operators.def: Remove stale comment.
+
2002-06-27 Mark Mitchell <mark@codesourcery.com>
PR c++/6695
diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c
index 2e79581..7bfbb4b 100644
--- a/gcc/cp/mangle.c
+++ b/gcc/cp/mangle.c
@@ -1818,6 +1818,12 @@ write_expression (expr)
write_mangled_name (expr);
write_char ('E');
}
+ else if (TREE_CODE (expr) == SIZEOF_EXPR
+ && TYPE_P (TREE_OPERAND (expr, 0)))
+ {
+ write_string ("st");
+ write_type (TREE_OPERAND (expr, 0));
+ }
else
{
int i;
@@ -1856,6 +1862,7 @@ write_expression (expr)
write_expression (TREE_OPERAND (expr, 0));
break;
+
/* Handle pointers-to-members specially. */
case SCOPE_REF:
write_type (TREE_OPERAND (expr, 0));
diff --git a/gcc/cp/operators.def b/gcc/cp/operators.def
index 775f59d..8504380 100644
--- a/gcc/cp/operators.def
+++ b/gcc/cp/operators.def
@@ -5,7 +5,7 @@
non-overloadable operators (like the `?:' ternary operator).
Writtey by Mark Mitchell <mark@codesourcery.com>
- Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of GNU CC.
@@ -46,10 +46,6 @@ Boston, MA 02111-1307, USA. */
mangled under the new ABI. For `operator +', for example, this
would be "pl".
- OLD_MANGLING
-
- Analogous, but for the old ABI.
-
ARITY
The arity of the operator, or -1 if any arity is allowed. (As
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e5900c5..78f24d8 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2002-07-01 Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/7112
+ * g++.dg/template/sizeof1.C: New test.
+
2002-07-01 Hans-Peter Nilsson <hp@axis.com>
PR target/7177
diff --git a/gcc/testsuite/g++.dg/template/sizeof1.C b/gcc/testsuite/g++.dg/template/sizeof1.C
index 328d647..76d1cf4 100644
--- a/gcc/testsuite/g++.dg/template/sizeof1.C
+++ b/gcc/testsuite/g++.dg/template/sizeof1.C
@@ -1,15 +1,23 @@
-// Test use of `sizeof' as a template parameter.
-// Origin: smacdonald@seimac.com
-
// { dg-do compile }
-template <unsigned I> struct A {};
+template<int size>
+struct Foobar {
+ // Contents irrelevant
+};
+
+template <typename A>
+struct Wrapper {
+ // Contents irrelevant
+};
-template <typename SizeType>
-struct B
+template <typename A>
+Foobar<sizeof(Wrapper<A>)> *
+compiler_bug (A)
{
-char * f() const
+ return 0;
+}
+
+int main()
{
-return (A<sizeof(void *)>::value);
+ compiler_bug(1);
}
-};
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index d795263..123242b 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,9 @@
+2002-07-01 Mark Mitchell <mark@codesourcery.com>
+
+ * cp-demangle.c (demangle_operator_name): Add type_arg parameter.
+ Set it for the "st" operator.
+ (demangle_expression): Handle expressions with types as arguments.
+
2002-05-31 Roman Lechtchinsky <rl@cs.tu-berlin.de>
* configure.in: Fix typo in the code checking for sys_errlist.
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 53eeaaf..162aafc 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -1,5 +1,5 @@
/* Demangler for IA64 / g++ V3 ABI.
- Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
Written by Alex Samuel <samuel@codesourcery.com>.
This file is part of GNU CC.
@@ -898,7 +898,7 @@ static status_t demangle_number_literally
static status_t demangle_identifier
PARAMS ((demangling_t, int, dyn_string_t));
static status_t demangle_operator_name
- PARAMS ((demangling_t, int, int *));
+ PARAMS ((demangling_t, int, int *, int *));
static status_t demangle_nv_offset
PARAMS ((demangling_t));
static status_t demangle_v_offset
@@ -1325,7 +1325,7 @@ demangle_unqualified_name (dm, suppress_return_type)
if (peek == 'c' && peek_char_next (dm) == 'v')
*suppress_return_type = 1;
- RETURN_IF_ERROR (demangle_operator_name (dm, 0, &num_args));
+ RETURN_IF_ERROR (demangle_operator_name (dm, 0, &num_args, NULL));
}
else if (peek == 'C' || peek == 'D')
{
@@ -1501,7 +1501,9 @@ demangle_identifier (dm, length, identifier)
/* Demangles and emits an <operator-name>. If SHORT_NAME is non-zero,
the short form is emitted; otherwise the full source form
(`operator +' etc.) is emitted. *NUM_ARGS is set to the number of
- operands that the operator takes.
+ operands that the operator takes. If TYPE_ARG is non-NULL,
+ *TYPE_ARG is set to 1 if the first argument is a type and 0
+ otherwise.
<operator-name>
::= nw # new
@@ -1551,15 +1553,17 @@ demangle_identifier (dm, length, identifier)
::= cl # ()
::= ix # []
::= qu # ?
- ::= sz # sizeof
+ ::= st # sizeof (a type)
+ ::= sz # sizeof (an expression)
::= cv <type> # cast
::= v [0-9] <source-name> # vendor extended operator */
static status_t
-demangle_operator_name (dm, short_name, num_args)
+demangle_operator_name (dm, short_name, num_args, type_arg)
demangling_t dm;
int short_name;
int *num_args;
+ int *type_arg;
{
struct operator_code
{
@@ -1633,6 +1637,10 @@ demangle_operator_name (dm, short_name, num_args)
DEMANGLE_TRACE ("operator-name", dm);
+ /* Assume the first argument is not a type. */
+ if (type_arg)
+ *type_arg = 0;
+
/* Is this a vendor-extended operator? */
if (c0 == 'v' && IS_DIGIT (c1))
{
@@ -1652,6 +1660,16 @@ demangle_operator_name (dm, short_name, num_args)
return STATUS_OK;
}
+ /* Is it the sizeof variant that takes a type? */
+ if (c0 == 's' && c1 == 't')
+ {
+ RETURN_IF_ERROR (result_add (dm, " sizeof"));
+ *num_args = 1;
+ if (type_arg)
+ *type_arg = 1;
+ return STATUS_OK;
+ }
+
/* Perform a binary search for the operator code. */
while (1)
{
@@ -3154,6 +3172,7 @@ demangle_expression (dm)
/* An operator expression. */
{
int num_args;
+ int type_arg;
status_t status = STATUS_OK;
dyn_string_t operator_name;
@@ -3161,7 +3180,8 @@ demangle_expression (dm)
operations in infix notation, capture the operator name
first. */
RETURN_IF_ERROR (result_push (dm));
- RETURN_IF_ERROR (demangle_operator_name (dm, 1, &num_args));
+ RETURN_IF_ERROR (demangle_operator_name (dm, 1, &num_args,
+ &type_arg));
operator_name = (dyn_string_t) result_pop (dm);
/* If it's binary, do an operand first. */
@@ -3182,7 +3202,10 @@ demangle_expression (dm)
/* Emit its second (if binary) or only (if unary) operand. */
RETURN_IF_ERROR (result_add_char (dm, '('));
- RETURN_IF_ERROR (demangle_expression (dm));
+ if (type_arg)
+ RETURN_IF_ERROR (demangle_type (dm));
+ else
+ RETURN_IF_ERROR (demangle_expression (dm));
RETURN_IF_ERROR (result_add_char (dm, ')'));
/* The ternary operator takes a third operand. */