+2005-04-25 Roger Sayle <roger@eyesopen.com>
+ Mark Mitchell <mark@codesourcery.com>
+
+ PR c++/20995
+ Partial backport from mainline.
+ 2004-09-27 Mark Mitchell <mark@codesourcery.com>
+ * tree.c (fold_if_not_in_template): New function.
+ * cp-tree.h (fold_if_not_in_template): Prototype here.
+ * call.c (build_conditional_expr): Use fold_if_not_in_template.
+ * typeck.c (build_binary_op): Likewise.
+
2005-04-16 Mark Mitchell <mark@codesourcery.com>
PR c++/21025
/* Functions related to invoking methods and overloaded functions.
Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com) and
modified by Brendan Kehoe (brendan@cygnus.com).
}
valid_operands:
- result = fold (build (COND_EXPR, result_type, arg1, arg2, arg3));
+ result = fold_if_not_in_template (build (COND_EXPR, result_type,
+ arg1, arg2, arg3));
/* We can't use result_type below, as fold might have returned a
throw_expr. */
/* Definitions for C++ parsing and type checking.
Copyright (C) 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
extern tree cp_add_pending_fn_decls (void*,tree);
extern int cp_is_overload_p (tree);
extern int cp_auto_var_in_fn_p (tree,tree);
+extern tree fold_if_not_in_template (tree);
extern tree cp_copy_res_decl_for_inlining (tree, tree, tree, void*,
int*, tree);
/* Language-dependent node constructors for parse phase of GNU compiler.
Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
return true;
}
+/* Like "fold", but should be used whenever we might be processing the
+ body of a template. */
+
+tree
+fold_if_not_in_template (tree expr)
+{
+ /* In the body of a template, there is never any need to call
+ "fold". We will call fold later when actually instantiating the
+ template. Integral constant expressions in templates will be
+ evaluated via fold_non_dependent_expr, as necessary. */
+ return (processing_template_decl ? expr : fold (expr));
+}
+
\f
#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
/* Complain that some language-specific thing hanging off a tree
/* Build expressions with type checking for C++ compiler.
Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GCC.
tree result = build (resultcode, build_type, op0, op1);
tree folded;
- folded = fold (result);
+ folded = fold_if_not_in_template (result);
if (folded == result)
TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
if (final_type != 0)
+2005-04-25 Roger Sayle <roger@eyesopen.com>
+
+ PR c++/20995
+ * g++.dg/opt/pr20995-1.C: New test case.
+
2005-04-16 Mark Mitchell <mark@codesourcery.com>
PR c++/21025
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+template<int N> void foo()
+{
+ double d = (N ? 0.0 : 0) + 1;
+}
+