This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH, committed] [PR15064] typeid operator cannot appear in integral constant expressions
- From: "Giovanni Bajo" <giovannibajo at libero dot it>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 22 Apr 2004 18:57:44 +0200
- Subject: [C++ PATCH, committed] [PR15064] typeid operator cannot appear in integral constant expressions
Hello,
PR c++/15064 is another fallout of my patch to fold non-dependent initializers
in templates. As the other PRs we managed to fix before 3.4.0 was released, the
problem is that the parser doesn't acknowledge typeid operator to be invalid as
an integral constant expression.
Fixed thus, tested on i686-pc-linux-gnu. I will commit tomorrow to mainline and
3.4 if nobody objects.
Giovanni Bajo
cp/
2004-04-19 Giovanni Bajo <giovannibajo@gcc.gnu.org>
PR c++/15064
* parser.c (cp_parser_postfix_expression): typeid operator cannot be
used in integral constant expressions.
testsuite/
2004-04-19 Giovanni Bajo <giovannibajo@gcc.gnu.org>
PR c++/15064
* g++.dg/template/crash18.C: New test.
Index: parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.188
diff -c -3 -p -r1.188 parser.c
*** parser.c 30 Mar 2004 19:19:01 -0000 1.188
--- parser.c 22 Apr 2004 15:33:56 -0000
*************** cp_parser_postfix_expression (cp_parser
*** 3594,3600 ****
/* Look for the `)' token. */
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
}
!
/* Restore the saved message. */
parser->type_definition_forbidden_message = saved_message;
}
--- 3594,3603 ----
/* Look for the `)' token. */
cp_parser_require (parser, CPP_CLOSE_PAREN, "`)'");
}
! /* `typeid' may not appear in an integral constant expression. */
! if (cp_parser_non_integral_constant_expression(parser,
! "`typeid' operator"))
! return error_mark_node;
/* Restore the saved message. */
parser->type_definition_forbidden_message = saved_message;
}
// { dg-do compile }
// Contributed by: <leif dot lonnblad at thep dot lu dot se>
// PR c++/15064: typeid does not form an integral constant expression
#include <typeinfo>
template <typename T>
void dummy() {
const std::type_info& t = typeid(T);
const std::type_info& t2 = typeid(float);
}
template void dummy<int>(void);