+2020-02-03 Jason Merrill <jason@redhat.com>
+
+ PR c++/91953
+ * constexpr.c (potential_constant_expression_1) [PARM_DECL]: Allow
+ empty class type.
+ [COMPONENT_REF]: A member function reference doesn't use the object
+ as an rvalue.
+
2020-02-03 Iain Sandoe <iain@sandoe.co.uk>
PR c++/93458
return true;
case PARM_DECL:
- if (now)
+ if (now && want_rval)
{
+ tree type = TREE_TYPE (t);
+ if (dependent_type_p (type)
+ || is_really_empty_class (type, /*ignore_vptr*/false))
+ /* An empty class has no data to read. */
+ return true;
if (flags & tf_error)
error ("%qE is not a constant expression", t);
return false;
#endif
return RECUR (t, any);
- case REALPART_EXPR:
- case IMAGPART_EXPR:
case COMPONENT_REF:
- case BIT_FIELD_REF:
case ARROW_EXPR:
case OFFSET_REF:
/* -- a class member access unless its postfix-expression is
postfix-expression being a potential constant expression. */
if (type_unknown_p (t))
return true;
+ if (is_overloaded_fn (t))
+ /* In a template, a COMPONENT_REF of a function expresses ob.fn(),
+ which uses ob as an lvalue. */
+ want_rval = false;
+ gcc_fallthrough ();
+
+ case REALPART_EXPR:
+ case IMAGPART_EXPR:
+ case BIT_FIELD_REF:
return RECUR (TREE_OPERAND (t, 0), want_rval);
case EXPR_PACK_EXPANSION:
// { dg-do compile { target c++17 } }
struct T {
+ int i;
constexpr auto foo() { return false; }
};
template <class MustBeTemplate>
constexpr auto bf(T t) {
- if constexpr(t.foo()) { // { dg-error "constant expression" }
+ if constexpr(t.foo()) {
return false;
}
return true;