From 47d4c811980d2793dc7502bd3949de2bac374304 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 20 Aug 2003 18:00:09 +0000 Subject: [PATCH] re PR c++/11945 (Incorrect warnings issued for comma-expressions inside templates) cp: PR c++/11945 * pt.c (build_non_dependent_expr): Look inside COND_EXPR and COMPOUND_EXPR. * semantics.c (finish_expr_stmt): Always convert to void. * typeck.c (build_x_compound_exp): Always convert to void. testsuite: PR c++/11945 * g++.dg/warn/noeffect2.C: New test. From-SVN: r70606 --- gcc/cp/ChangeLog | 8 ++++++++ gcc/cp/pt.c | 13 +++++++++++++ gcc/cp/semantics.c | 2 ++ gcc/cp/typeck.c | 7 ++----- gcc/testsuite/ChangeLog | 8 ++++++++ gcc/testsuite/g++.dg/warn/noeffect2.C | 18 ++++++++++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/noeffect2.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5a7bd6878956..7dcf9c2dc29e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2003-08-20 Nathan Sidwell + + PR c++/11945 + * pt.c (build_non_dependent_expr): Look inside COND_EXPR and + COMPOUND_EXPR. + * semantics.c (finish_expr_stmt): Always convert to void. + * typeck.c (build_x_compound_exp): Always convert to void. + 2003-08-19 Mark Mitchell PR c++/11684 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 863ab86ad19b..20642c385425 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11797,6 +11797,19 @@ build_non_dependent_expr (tree expr) types. */ if (TREE_CODE (expr) == OVERLOAD) return expr; + + if (TREE_CODE (expr) == COND_EXPR) + return build (COND_EXPR, + TREE_TYPE (expr), + TREE_OPERAND (expr, 0), + build_non_dependent_expr (TREE_OPERAND (expr, 1)), + build_non_dependent_expr (TREE_OPERAND (expr, 2))); + if (TREE_CODE (expr) == COMPOUND_EXPR) + return build (COMPOUND_EXPR, + TREE_TYPE (expr), + TREE_OPERAND (expr, 0), + build_non_dependent_expr (TREE_OPERAND (expr, 1))); + /* Otherwise, build a NON_DEPENDENT_EXPR. REFERENCE_TYPEs are not stripped for expressions in templates diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2997237b06ae..78a7f06413ad 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -421,6 +421,8 @@ finish_expr_stmt (tree expr) { if (!processing_template_decl) expr = convert_to_void (expr, "statement"); + else if (!type_dependent_expression_p (expr)) + convert_to_void (build_non_dependent_expr (expr), "statement"); r = add_stmt (build_stmt (EXPR_STMT, expr)); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 21186ebca818..ed9b6b9450f7 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -4309,11 +4309,8 @@ build_x_compound_expr (tree op1, tree op2) tree build_compound_expr (tree lhs, tree rhs) { - if (!processing_template_decl) - { - lhs = decl_constant_value (lhs); - lhs = convert_to_void (lhs, "left-hand operand of comma"); - } + lhs = decl_constant_value (lhs); + lhs = convert_to_void (lhs, "left-hand operand of comma"); if (lhs == error_mark_node || rhs == error_mark_node) return error_mark_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1020020022bf..bbbf552c5305 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-08-20 Nathan Sidwell + + PR c++/11945 + * g++.dg/warn/noeffect2.C: New test. + 2003-08-19 Mark Mitchell PR c++/10926 @@ -54,6 +59,9 @@ 2003-08-18 Nathan Sidwell + PR c++/11957 + * g++.dg/warn/noeffect1.C: New test. + * g++.dg/template/scope2.C: New test. * g++.dg/template/error2.C: Correct dg-error diff --git a/gcc/testsuite/g++.dg/warn/noeffect2.C b/gcc/testsuite/g++.dg/warn/noeffect2.C new file mode 100644 index 000000000000..7bd2925f542f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/noeffect2.C @@ -0,0 +1,18 @@ +// { dg-do compile } +// { dg-options "-Wall" } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 18 Aug 2003 +// Origin PR 11945 gerald@pfeifer.com + +// PR 11945 inconsistent warnings + +extern "C" void FormatDisk(); + template + struct C { + C(){ FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" } + }; + template + void f() { FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" } +void g() { FormatDisk(), 0; } // { dg-warning "right-hand operand of comma" "" } + -- 2.43.5