]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Allow parm of empty class type in constexpr.
authorJason Merrill <jason@redhat.com>
Mon, 2 Mar 2020 19:42:47 +0000 (14:42 -0500)
committerJason Merrill <jason@redhat.com>
Mon, 2 Mar 2020 20:49:58 +0000 (15:49 -0500)
commitb4e53e9b3c963b1c0fe9637618dec8042764f599
tree0032767bbbe11287e921f5bc1f0c57867ebfa7b5
parentf137a7c6b122e524294fb792bb97d5f3b0600c4f
c++: Allow parm of empty class type in constexpr.

Since copying a class object is defined in terms of the copy constructor,
copying an empty class is OK even if it would otherwise not be usable in a
constant expression.  Relatedly, using a parameter as an lvalue is no more
problematic than a local variable, and calling a member function uses the
object as an lvalue.

gcc/cp/ChangeLog
2020-03-02  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.
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-empty14.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/constexpr-if12.C