aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2015-06-01 22:28:25 -0400
committerJason Merrill <jason@gcc.gnu.org>2015-06-01 22:28:25 -0400
commit81371eff9bc7ef26172c925c923fdd28ac3622ce (patch)
treee73101948543e48f9fa6eaa1f25cffe11c9ab0be
parent603eaec49a32f4b409ca8c22e71e6f683c799758 (diff)
downloadgcc-81371eff9bc7ef26172c925c923fdd28ac3622ce.zip
gcc-81371eff9bc7ef26172c925c923fdd28ac3622ce.tar.gz
gcc-81371eff9bc7ef26172c925c923fdd28ac3622ce.tar.bz2
re PR c++/65942 ([C++14] cannot use std::function as comparator in algorithms)
PR c++/65942 * decl2.c (mark_used): Don't always instantiate constexpr fns. * constexpr.c (cxx_eval_call_expression): Instantiate them here. From-SVN: r224008
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/constexpr.c9
-rw-r--r--gcc/cp/decl2.c3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-decltype2.C7
4 files changed, 21 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 78d7791..be1a3f9 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2015-06-01 Jason Merrill <jason@redhat.com>
+ PR c++/65942
+ * decl2.c (mark_used): Don't always instantiate constexpr fns.
+ * constexpr.c (cxx_eval_call_expression): Instantiate them here.
+
PR c++/44282
* mangle.c (attr_strcmp): New.
(write_CV_qualifiers_for_type): Also write out attributes that
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index ff5489f..d05372a 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1240,6 +1240,15 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
return build_zero_init (DECL_CONTEXT (fun), NULL_TREE, false);
}
+ /* We can't defer instantiating the function any longer. */
+ if (!DECL_INITIAL (fun)
+ && DECL_TEMPLOID_INSTANTIATION (fun))
+ {
+ ++function_depth;
+ instantiate_decl (fun, /*defer_ok*/false, /*expl_inst*/false);
+ --function_depth;
+ }
+
/* If in direct recursive call, optimize definition search. */
if (ctx && ctx->call && ctx->call->fundef->decl == fun)
new_call.fundef = ctx->call->fundef;
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index f1b3d0c..8ba19cf 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -5046,8 +5046,7 @@ mark_used (tree decl, tsubst_flags_t complain)
&& DECL_TEMPLATE_INFO (decl)
&& (decl_maybe_constant_var_p (decl)
|| (TREE_CODE (decl) == FUNCTION_DECL
- && (DECL_DECLARED_CONSTEXPR_P (decl)
- || DECL_OMP_DECLARE_REDUCTION_P (decl)))
+ && DECL_OMP_DECLARE_REDUCTION_P (decl))
|| undeduced_auto_decl (decl))
&& !uses_template_parms (DECL_TI_ARGS (decl)))
{
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-decltype2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-decltype2.C
new file mode 100644
index 0000000..15ca995
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-decltype2.C
@@ -0,0 +1,7 @@
+// PR c++/65942
+// { dg-do compile { target c++11 } }
+
+template <typename T> constexpr int f(T t) { return t; }
+template <typename T, typename = decltype(f(T()))> void g(T) { }
+void g(...) { }
+int main() { g(""); }