This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] Fix PR/10750 (a regression)


Hello,

a valid constant expression is a static const member initialized with a
TREE_CONST. But it might also be a static const member initialized with a
dependent expression (or at least, there is no reason to reject such a
construct at parsing time). I guess this regression was introduced with the
new parser.

Bootstrapped on i686-pc-cygwin (c, c++, and java), and tested with
"make check-g++" with no new regressions.

OK for mainline?

Giovanni Bajo


2003-06-17  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/10750
        * parser.c (cp_parser_primary_expression): A VAR_DECL with a
        (value- or type-) dependent expression as DECL_INITIAL is a
        valid constant-expression (at parser time).

2003-06-17  Giovanni Bajo  <giovannibajo@libero.it>

        PR c++/10750
        * g++.dg/parse/constant2.C: New test.


Index: parser.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.63
diff -c -w -r1.63 parser.c
*** parser.c 25 May 2003 12:59:22 -0000 1.63
--- parser.c 17 Jun 2003 16:16:34 -0000
***************
*** 2783,2793 ****
         && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
    /* Const variables or static data members of integral
       or enumeration types initialized with constant
!      expressions.  */
    && !(TREE_CODE (decl) == VAR_DECL
         && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
         && DECL_INITIAL (decl)
!        && TREE_CONSTANT (DECL_INITIAL (decl))))
         {
    if (!parser->allow_non_constant_expression_p)
      return cp_parser_non_constant_id_expression (decl);
--- 2783,2798 ----
         && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl)))
    /* Const variables or static data members of integral
       or enumeration types initialized with constant
!      expressions (or dependent expressions - in this case
!      the check will be done at instantiation time). */
    && !(TREE_CODE (decl) == VAR_DECL
         && INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
         && DECL_INITIAL (decl)
!        && (TREE_CONSTANT (DECL_INITIAL (decl))
!     || type_dependent_expression_p 
!        (DECL_INITIAL (decl))
!     || value_dependent_expression_p 
!        (DECL_INITIAL (decl)))))
         {
    if (!parser->allow_non_constant_expression_p)
      return cp_parser_non_constant_id_expression (decl);


// { dg-do compile }
// Origin: <gawrilow at math dot tu-berlin dot de>
// PR c++/10750: error when using a static const member initialized 
//  with a dependent expression as constant-expression

struct A
{
  enum { a = 42 };
};

template <class Q>
struct B
{
  static const int b = Q::a;
};

template <typename T, template <typename> class P>
struct C
{
  static const bool a = T::a;
  static const bool a_ = a;
  static const bool b = P<T>::b;
  static const bool b_ = b;
  static const int c = sizeof(T);
  static const int c_ = c;
};

template struct C<A,B>;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]