<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Aggregate initialization of struct containing zero-sized array disagrees with GCC"
   href="https://bugs.llvm.org/show_bug.cgi?id=36141">36141</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Aggregate initialization of struct containing zero-sized array disagrees with GCC
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Clang believes that an aggregate consisting of a zero-sized array and a 1-sized
array is NOT initializable with just one initializer in the curly braces,
whereas GCC believes that it IS.

prog.cc:15:16: error: initializer for aggregate with no elements requires
explicit braces
    auto x = A{convertible_to_anything{}};
               ^

It would be convenient if Clang matched GCC's behavior for zero-sized arrays.
The existing behavior is definitely not a "bug bug", as zero-sized arrays are
non-standard and I'm not aware that Clang has *promised* to mimic GCC in this
area; but the discrepancy between the two compilers in this area is awkward for
testing.


#include <cstdio>
#include <type_traits>
#include <utility>

struct convertible_to_anything { template<class T> constexpr operator T&()
const noexcept; };
template<class T, class, class> struct is_n_constructible_impl :
std::false_type {};
template<class T, size_t... Is> struct is_n_constructible_impl<T,
std::index_sequence<Is...>, decltype(void(T{(void(Is),
convertible_to_anything{})...}))> : std::true_type {};

template<size_t N, class T> struct is_n_constructible :
is_n_constructible_impl<T, std::make_index_sequence<N>, void> {};


struct A { int a[0]; int b[1]; };

int main() {
    static_assert(is_n_constructible<0, A>::value);
    if (is_n_constructible<1, A>::value) {
        puts("This is GCC");
    } else {
        puts("This is Clang");
    }
    static_assert(not is_n_constructible<2, A>::value);
    static_assert(not is_n_constructible<3, A>::value);
}</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>