Hi,
On 02/05/2014 10:28 PM, Jason Merrill wrote:
On 02/05/2014 11:19 AM, Paolo Carlini wrote:
if (vec_safe_is_empty (vbases))
/* No virtual bases to worry about. */;
else if (!assign_p)
{
if (constexpr_p)
*constexpr_p = false;
*constexpr_p should be false for a constructor of a class with virtual
bases, according to the standard (7.1.5p4):
The definition of a constexpr constructor shall satisfy the following
constraints:
— the class shall not have any virtual base classes;
...
So the assert in implicit_declare_fn is wrong. I guess I would fix it
by checking CLASSTYPE_VBASECLASSES.
Ah! It didn't occur to me that the bug could be in the gcc_assert
itself. Thus, thanks, I tested on x86_64-linux the below.
Paolo.
//////////////////////
/cp
2014-02-06 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/60047
* method.c (implicitly_declare_fn): A constructor of a class with
virtual base classes isn't constexpr (7.1.5p4).
(synthesized_method_walk): Revert PR58871 change.
/testsuite
2014-02-06 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/60047
* g++.dg/cpp0x/pr60047.C: New.
Index: cp/method.c
===================================================================
--- cp/method.c (revision 207536)
+++ cp/method.c (working copy)
@@ -1366,7 +1366,7 @@ synthesized_method_walk (tree ctype, special_funct
}
vbases = CLASSTYPE_VBASECLASSES (ctype);
- if (vec_safe_is_empty (vbases))
+ if (vbases == NULL)
/* No virtual bases to worry about. */;
else if (!assign_p)
{
@@ -1656,10 +1656,12 @@ implicitly_declare_fn (special_function_kind kind,
/* Don't bother marking a deleted constructor as constexpr. */
if (deleted_p)
constexpr_p = false;
- /* A trivial copy/move constructor is also a constexpr constructor. */
+ /* A trivial copy/move constructor is also a constexpr constructor,
+ unless the class has virtual bases (7.1.5p4). */
else if (trivial_p && cxx_dialect >= cxx11
&& (kind == sfk_copy_constructor
- || kind == sfk_move_constructor))
+ || kind == sfk_move_constructor)
+ && !CLASSTYPE_VBASECLASSES (type))
gcc_assert (constexpr_p);
if (!trivial_p && type_has_trivial_fn (type, kind))
Index: testsuite/g++.dg/cpp0x/pr60047.C
===================================================================
--- testsuite/g++.dg/cpp0x/pr60047.C (revision 0)
+++ testsuite/g++.dg/cpp0x/pr60047.C (working copy)
@@ -0,0 +1,14 @@
+// PR c++/60047
+// { dg-do compile { target c++11 } }
+
+struct B { };
+
+template<typename T> struct A : virtual B
+{
+ A();
+ A(const A&);
+};
+
+template<typename T> A<T>::A(const A<T>&) = default;
+
+A<int> a = A<int>();