+2014-08-27 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/52892
+ * semantics.c (cxx_eval_call_expression): Use STRIP_NOPS on the
+ result of cxx_eval_constant_expression.
+
2014-08-26 Jason Merrill <jason@redhat.com>
PR c++/58624
{
/* Might be a constexpr function pointer. */
fun = cxx_eval_constant_expression (old_call, fun, allow_non_constant,
- /*addr*/false, non_constant_p, overflow_p);
+ /*addr*/false, non_constant_p,
+ overflow_p);
+ STRIP_NOPS (fun);
if (TREE_CODE (fun) == ADDR_EXPR)
fun = TREE_OPERAND (fun, 0);
}
+2014-08-27 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/52892
+ * g++.dg/cpp0x/constexpr-52892-1.C: New.
+ * g++.dg/cpp0x/constexpr-52892-2.C: Likewise.
+ * g++.dg/cpp0x/constexpr-52282-1.C: Likewise.
+
2014-08-27 Guozhi Wei <carrot@google.com>
PR target/62262
--- /dev/null
+// PR c++/52282
+// { dg-do compile { target c++11 } }
+
+template <typename T, T V>
+struct A
+ {
+ static constexpr T a() { return V; }
+ };
+
+template <typename T, T V>
+struct B
+ {
+ typedef T type;
+ static constexpr type b() { return V; }
+ };
+
+template <typename T, T V>
+struct C
+ {
+ static constexpr decltype(V) c() { return V; }
+ };
+static_assert(A<int, 10>::a() == 10, "oops");
+static_assert(B<int, 10>::b() == 10, "oops");
+static_assert(C<int, 10>::c() == 10, "oops");
+
+struct D
+ {
+ static constexpr int d() { return 10; }
+ };
+static_assert((A<int(*)(), &D::d>::a())() == 10, "oops");
+static_assert((B<int(*)(), &D::d>::b())() == 10, "oops");
+static_assert((C<int(*)(), &D::d>::c())() == 10, "oops");
--- /dev/null
+// PR c++/52892
+// { dg-do compile { target c++11 } }
+
+constexpr __SIZE_TYPE__ fibonacci(__SIZE_TYPE__ val) {
+ return (val <= 2) ? 1 : fibonacci(val - 1) + fibonacci(val - 2);
+}
+
+template <typename Function>
+struct Defer {
+ constexpr Defer(const Function func_) : func(func_) { }
+
+ const Function func;
+
+ template <typename... Args>
+ constexpr auto operator () (const Args&... args) -> decltype(func(args...)) {
+ return func(args...);
+ }
+};
+
+template <typename Function>
+constexpr Defer<Function> make_deferred(const Function f) {
+ return Defer<Function>(f);
+}
+
+int main() {
+ constexpr auto deferred = make_deferred(&fibonacci);
+ static_assert(deferred(25) == 75025, "Static fibonacci call failed");
+}
--- /dev/null
+// PR c++/52892
+// { dg-do compile { target c++11 } }
+
+constexpr bool is_negative(int x) { return x < 0; }
+typedef bool (*Function)(int);
+constexpr bool check(int x, Function p) { return p(x); }
+static_assert(check(-2, is_negative), "Error");