1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// This code triggers https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104568
10// UNSUPPORTED: msvc
11
12// Test the fix for https://llvm.org/PR54100
13
14#include <memory>
15#include <cassert>
16
17#include "test_macros.h"
18
19struct A {
20 int m[0];
21};
22static_assert(sizeof(A) == 0, ""); // an extension supported by GCC and Clang
23
24int main(int, char**)
25{
26 {
27 std::unique_ptr<A> p = std::unique_ptr<A>(new A);
28 assert(p != nullptr);
29 }
30 {
31 std::unique_ptr<A[]> p = std::unique_ptr<A[]>(new A[1]);
32 assert(p != nullptr);
33 }
34#if TEST_STD_VER > 11
35 {
36 std::unique_ptr<A> p = std::make_unique<A>();
37 assert(p != nullptr);
38 }
39 {
40 std::unique_ptr<A[]> p = std::make_unique<A[]>(1);
41 assert(p != nullptr);
42 }
43#endif
44
45 return 0;
46}
47

source code of libcxx/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.sizezero.pass.cpp