mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-30 18:26:05 +00:00

Based on post-commit review discussion on 2bd84938470bf2e337801faafb8a67710f46429d with Richard Smith. Other uses of forcing HasEmptyPlaceHolder to false seem OK to me - they're all around pointer/reference types where the pointer/reference token will appear at the rightmost side of the left side of the type name, so they make nested types (eg: the "int" in "int *") behave as though there is a non-empty placeholder (because the "*" is essentially the placeholder as far as the "int" is concerned). This was originally committed in 277623f4d5a672d707390e2c3eaf30a9eb4b075c Reverted in f9ad1d1c775a8e264bebc15d75e0c6e5c20eefc7 due to breakages outside of clang - lldb seems to have some strange/strong dependence on "char [N]" versus "char[N]" when printing strings (not due to that name appearing in DWARF, but probably due to using clang to stringify type names) that'll need to be addressed, plus a few other odds and ends in other subprojects (clang-tools-extra, compiler-rt, etc).
75 lines
2.7 KiB
C++
75 lines
2.7 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// UNSUPPORTED: c++03, c++11, c++14, c++17
|
|
// UNSUPPORTED: libcpp-no-concepts
|
|
|
|
// template<class T>
|
|
// concept default_initializable = constructible_from<T> &&
|
|
// requires { T{}; } &&
|
|
// is-default-initializable<T>;
|
|
|
|
#include <concepts>
|
|
#include <cassert>
|
|
|
|
#include "test_macros.h"
|
|
|
|
template<class T>
|
|
concept brace_initializable = requires { T{}; };
|
|
|
|
void test() {
|
|
// LWG3149
|
|
// Changed the concept from constructible_from<T>
|
|
// to constructible_from<T> &&
|
|
// requires { T{}; } && is-default-initializable <T>
|
|
struct S0 { explicit S0() = default; };
|
|
S0 x0;
|
|
S0 y0{};
|
|
static_assert(std::constructible_from<S0>);
|
|
static_assert(brace_initializable<S0>);
|
|
LIBCPP_STATIC_ASSERT(std::__default_initializable<S0>);
|
|
static_assert(std::default_initializable<S0>);
|
|
|
|
struct S1 { S0 x; }; // Note: aggregate
|
|
S1 x1;
|
|
S1 y1{}; // expected-error {{chosen constructor is explicit in copy-initialization}}
|
|
static_assert(std::constructible_from<S1>);
|
|
static_assert(!brace_initializable<S1>);
|
|
LIBCPP_STATIC_ASSERT(std::__default_initializable<S1>);
|
|
static_assert(!std::default_initializable<S1>);
|
|
|
|
const int x2; // expected-error {{default initialization of an object of const type 'const int'}}
|
|
const int y2{};
|
|
|
|
static_assert(std::constructible_from<const int>);
|
|
static_assert(brace_initializable<const int>);
|
|
LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int>);
|
|
static_assert(!std::default_initializable<const int>);
|
|
|
|
const int x3[1]; // expected-error {{default initialization of an object of const type 'const int[1]'}}
|
|
const int y3[1]{};
|
|
static_assert(std::constructible_from<const int[1]>);
|
|
static_assert(brace_initializable<const int[1]>);
|
|
LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int[1]>);
|
|
static_assert(!std::default_initializable<const int[1]>);
|
|
|
|
// Zero-length array extension
|
|
const int x4[]; // expected-error {{definition of variable with array type needs an explicit size or an initializer}}
|
|
const int y4[]{};
|
|
static_assert(!std::constructible_from<const int[]>);
|
|
static_assert(brace_initializable<const int[]>);
|
|
LIBCPP_STATIC_ASSERT(!std::__default_initializable<const int[]>);
|
|
static_assert(!std::default_initializable<const int[]>);
|
|
}
|
|
|
|
int main(int, char**) {
|
|
test();
|
|
|
|
return 0;
|
|
}
|