* C++ PATCH for c++/29000
@ 2007-08-28 16:58 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2007-08-28 16:58 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 138 bytes --]
Just needed to teach the dependent type machinery to look inside a
statement-expression.
Tested x86_64-pc-linux-gnu, applied to trunk.
[-- Attachment #2: stmt-temp.patch --]
[-- Type: text/x-patch, Size: 3138 bytes --]
2007-08-27 Jason Merrill <jason@redhat.com>
PR c++/29000
* pt.c (build_non_dependent_expr, type_dependent_expression_p):
Look inside STMT_EXPR.
* semantics.c (stmt_expr_value_expr): New fn.
* cp-tree.h: Declare it.
* g++.dg/ext/stmtexpr12.C: New test.
Index: cp/cp-tree.h
===================================================================
*** cp/cp-tree.h (revision 127859)
--- cp/cp-tree.h (working copy)
*************** extern tree finish_non_static_data_membe
*** 4609,4614 ****
--- 4609,4615 ----
extern tree begin_stmt_expr (void);
extern tree finish_stmt_expr_expr (tree, tree);
extern tree finish_stmt_expr (tree, bool);
+ extern tree stmt_expr_value_expr (tree);
extern tree perform_koenig_lookup (tree, tree);
extern tree finish_call_expr (tree, tree, bool, bool);
extern tree finish_increment_expr (tree, enum tree_code);
Index: cp/pt.c
===================================================================
*** cp/pt.c (revision 127859)
--- cp/pt.c (working copy)
*************** type_dependent_expression_p (tree expres
*** 15272,15277 ****
--- 15272,15280 ----
&& !DECL_TEMPLATE_TEMPLATE_PARM_P (expression))
return false;
+ if (TREE_CODE (expression) == STMT_EXPR)
+ expression = stmt_expr_value_expr (expression);
+
if (TREE_TYPE (expression) == unknown_type_node)
{
if (TREE_CODE (expression) == ADDR_EXPR)
*************** build_non_dependent_expr (tree expr)
*** 15612,15617 ****
--- 15615,15622 ----
/* Preserve OVERLOADs; the functions must be available to resolve
types. */
inner_expr = expr;
+ if (TREE_CODE (inner_expr) == STMT_EXPR)
+ inner_expr = stmt_expr_value_expr (inner_expr);
if (TREE_CODE (inner_expr) == ADDR_EXPR)
inner_expr = TREE_OPERAND (inner_expr, 0);
if (TREE_CODE (inner_expr) == COMPONENT_REF)
Index: cp/semantics.c
===================================================================
*** cp/semantics.c (revision 127859)
--- cp/semantics.c (working copy)
*************** finish_stmt_expr (tree stmt_expr, bool h
*** 1754,1759 ****
--- 1754,1778 ----
return result;
}
+ /* Returns the expression which provides the value of STMT_EXPR. */
+
+ tree
+ stmt_expr_value_expr (tree stmt_expr)
+ {
+ tree t = STMT_EXPR_STMT (stmt_expr);
+
+ if (TREE_CODE (t) == BIND_EXPR)
+ t = BIND_EXPR_BODY (t);
+
+ if (TREE_CODE (t) == STATEMENT_LIST)
+ t = STATEMENT_LIST_TAIL (t)->stmt;
+
+ if (TREE_CODE (t) == EXPR_STMT)
+ t = EXPR_STMT_EXPR (t);
+
+ return t;
+ }
+
/* Perform Koenig lookup. FN is the postfix-expression representing
the function (or functions) to call; ARGS are the arguments to the
call. Returns the functions to be considered by overload
Index: testsuite/g++.dg/ext/stmtexpr12.C
===================================================================
*** testsuite/g++.dg/ext/stmtexpr12.C (revision 0)
--- testsuite/g++.dg/ext/stmtexpr12.C (revision 0)
***************
*** 0 ****
--- 1,7 ----
+ // PR c++/29000
+ // { dg-options "" }
+
+ template<int> int foo()
+ {
+ return ({foo;})==0; // { dg-error "insufficient context" }
+ }
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-08-28 16:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-28 16:58 C++ PATCH for c++/29000 Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).