libpmemobj-cpp icon indicating copy to clipboard operation
libpmemobj-cpp copied to clipboard

{{ initializer }} fail with gcc-10

Open kilobyte opened this issue 6 years ago • 6 comments

/home/kilobyte/c/libpmemobj-cpp/tests/array_slice/array_slice.cpp:217:27: error: could not convert ‘{{1, 2, 3, 4, 5, 6}}’ from ‘<brace-enclosed initializer list>’ to ‘TestSuccess::C’ {aka ‘pmem::obj::array<double, 6>’}
  217 |  C c = {{1, 2, 3, 4, 5, 6}};
      |                           ^
      |                           |
      |                           <brace-enclosed initializer list>
/home/kilobyte/c/libpmemobj-cpp/tests/array_slice/array_slice.cpp:290:60: error: could not convert ‘{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}}’ from ‘<brace-enclosed initializer list>’ to ‘TestAbort::C’ {aka ‘pmem::obj::array<double, 15>’}
  290 |  C c = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
      |                                                            ^
      |                                                            |
      |                                                            <brace-enclosed initializer list>
/home/kilobyte/c/libpmemobj-cpp/tests/array_algorithms/array_algorithms.cpp:55:23: error: could not convert ‘{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}’ from ‘<brace-enclosed initializer list>’ to ‘pmem::obj::array<double, 10>’
   55 |         6, 7, 8, 9, 10};
      |                       ^
      |                       |
      |                       <brace-enclosed initializer list>

kilobyte avatar Dec 06 '19 13:12 kilobyte

For compilation with -std=c++11/14/17 this is probably a bug in a compiler: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92869

For -std=c++2a this is caused by: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1008r1.pdf and is not specific to g++, clang also fails here.

Because pmem::obj::array has to explicilty define ctors as defaulted (because of declaring custom assignment operators) it will not longer be an aggregate in C++20. We should probably add info in documentation do some workaround in tests when compiled with c++2a.

igchor avatar Dec 10 '19 13:12 igchor

We should probably also implement some additional constructor for pmem::obj::array when compiled with c++20 (for example with std::initializer_list), otherwise there will be no way to initialize array elements (other than by default ctor).

igchor avatar Dec 10 '19 13:12 igchor

After some experiments: passing std::initializer_list is not possible but we may do something like this:

    template <typename... Args>
    array(Args &&... args)
        : data{ std::forward<Args>(args)... }
    {
    }

igchor avatar Dec 11 '19 15:12 igchor

I'm afraid this is more urgent as Fedora has switched to unreleased gcc-10 already, and they're about to freeze. With obj-cpp being a header-only library, we can't really demand for it to be compiled with gcc-9 only — with gcc-10 being the default compiler, most users will hit this problem.

kilobyte avatar Feb 04 '20 10:02 kilobyte

And indeed, as you say — the version in Fedora has been fixed already.

The fixed version has also reached Debian — yesterday's didn't work, after upgrade today the bug is gone.

Yay. Closing time.

kilobyte avatar Feb 04 '20 16:02 kilobyte

We need to enable tests for now (using workaround) and later on, we need to fix the array implementation.

lukaszstolarczuk avatar Jul 07 '21 09:07 lukaszstolarczuk