[llvm-bugs] [Bug 36141] New: Aggregate initialization of struct containing zero-sized array disagrees with GCC

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jan 29 14:46:56 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36141

            Bug ID: 36141
           Summary: Aggregate initialization of struct containing
                    zero-sized array disagrees with GCC
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180129/8d9885bd/attachment.html>


More information about the llvm-bugs mailing list