[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaCXX / cxx11-default-member-initializers.cpp
blob9c18c73be8f68e8ff5675df9019740d2c98099b9
1 // RUN: %clang_cc1 -std=c++11 -verify %s -pedantic
2 // RUN: %clang_cc1 -std=c++20 -verify %s -pedantic
5 namespace PR31692 {
6 struct A {
7 struct X { int n = 0; } x;
8 // Trigger construction of X() from a SFINAE context. This must not mark
9 // any part of X as invalid.
10 static_assert(!__is_constructible(X), "");
11 // Check that X::n is not marked invalid.
12 double &r = x.n; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
14 // A::X can now be default-constructed.
15 static_assert(__is_constructible(A::X), "");
19 struct S {
20 } constexpr s;
21 struct C {
22 C(S);
24 class MemInit {
25 C m = s;
28 #if __cplusplus >= 202002L
29 // This test ensures cleanup expressions are correctly produced
30 // in the presence of default member initializers.
31 namespace PR136554 {
32 struct string {
33 constexpr string(const char*) {};
34 constexpr ~string();
36 struct S;
37 struct optional {
38 template <typename U = S>
39 constexpr optional(U &&) {}
41 struct S {
42 string a;
43 optional b;
44 int defaulted = 0;
45 } test {
46 "", {
47 { "", 0 }
51 // Ensure that the this pointer is
52 // transformed without crashing
53 consteval int immediate() { return 0;}
54 struct StructWithThisInInitializer {
55 int member() const {
56 return 0;
58 int m = member() + immediate();
59 int m2 = this->member() + immediate();
62 template <typename T>
63 struct StructWithThisInInitializerTPL {
64 template <typename U>
65 int member() const {
66 return 0;
68 int m = member<int>() + immediate();
69 int m2 = this->member<int>() + immediate();
72 void test_this() {
73 (void)StructWithThisInInitializer{};
74 (void)StructWithThisInInitializerTPL<int>{};
77 struct ReferenceToNestedMembers {
78 int m;
79 int a = ((void)immediate(), m); // ensure g is found in the correct scope
80 int b = ((void)immediate(), this->m); // ensure g is found in the correct scope
82 struct ReferenceToNestedMembersTest {
83 void* m = nullptr;
84 ReferenceToNestedMembers j{0};
85 } test_reference_to_nested_members;
90 namespace odr_in_unevaluated_context {
91 template <typename e, bool = __is_constructible(e)> struct f {
92 using type = bool;
95 template <class k, f<k>::type = false> int l;
96 int m;
97 struct p {
98 // This used to crash because m is first marked odr used
99 // during parsing, but subsequently used in an unevaluated context
100 // without being transformed.
101 int o = m;
102 p() {}
105 int i = l<p>;
108 #endif