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: PR 23914


This patch fixes PR c++/23914, yet another static data member problem.
(The idea that we try to skip evaluating things inside "sizeof" turns
out to be rather less simple, now that we correctly refrain from
instantiating static data member initializers until needed.)

Tested on x86_64-unknown-linux-gnu, applied on the mainline and on the
4.0 branch.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2005-09-16  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23914
	* parser.c (cp_parser_enclosed_template_argument_list): Make sure
	skip_evaluation is false when processing template arguments.

2005-09-16  Mark Mitchell  <mark@codesourcery.com>

	PR c++/23914
	* g++.dg/template/static18.C: New test.

Index: gcc/cp/parser.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/parser.c,v
retrieving revision 1.358
diff -c -5 -p -r1.358 parser.c
*** gcc/cp/parser.c	13 Sep 2005 02:41:04 -0000	1.358
--- gcc/cp/parser.c	16 Sep 2005 15:59:23 -0000
*************** cp_parser_enclosed_template_argument_lis
*** 15409,15418 ****
--- 15409,15419 ----
    tree arguments;
    tree saved_scope;
    tree saved_qualifying_scope;
    tree saved_object_scope;
    bool saved_greater_than_is_operator_p;
+   bool saved_skip_evaluation;
  
    /* [temp.names]
  
       When parsing a template-id, the first non-nested `>' is taken as
       the end of the template-argument-list rather than a greater-than
*************** cp_parser_enclosed_template_argument_lis
*** 15423,15432 ****
--- 15424,15437 ----
    /* Parsing the argument list may modify SCOPE, so we save it
       here.  */
    saved_scope = parser->scope;
    saved_qualifying_scope = parser->qualifying_scope;
    saved_object_scope = parser->object_scope;
+   /* We need to evaluate the template arguments, even though this
+      template-id may be nested within a "sizeof".  */
+   saved_skip_evaluation = skip_evaluation;
+   skip_evaluation = false;
    /* Parse the template-argument-list itself.  */
    if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER))
      arguments = NULL_TREE;
    else
      arguments = cp_parser_template_argument_list (parser);
*************** cp_parser_enclosed_template_argument_lis
*** 15472,15481 ****
--- 15477,15487 ----
      = saved_greater_than_is_operator_p;
    /* Restore the SAVED_SCOPE.  */
    parser->scope = saved_scope;
    parser->qualifying_scope = saved_qualifying_scope;
    parser->object_scope = saved_object_scope;
+   skip_evaluation = saved_skip_evaluation;
  
    return arguments;
  }
  
  /* MEMBER_FUNCTION is a member function, or a friend.  If default
Index: gcc/testsuite/g++.dg/template/static18.C
===================================================================
RCS file: gcc/testsuite/g++.dg/template/static18.C
diff -N gcc/testsuite/g++.dg/template/static18.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- gcc/testsuite/g++.dg/template/static18.C	16 Sep 2005 15:59:23 -0000
***************
*** 0 ****
--- 1,13 ----
+ // PR c++/23914
+ 
+ template <class T> 
+ struct foo_template { 
+   static const unsigned complexity = 0; 
+ }; 
+  
+ template <int x> struct STATIC_ASSERTION {}; 
+  
+ void gcc_402_problem_minimal() 
+ { 
+   sizeof(STATIC_ASSERTION< foo_template<int>::complexity >); 
+ } 


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