Clang Project

clang_source_code/test/CXX/drs/dr17xx.cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4// RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5
6#if __cplusplus < 201103L
7// expected-no-diagnostics
8#endif
9
10namespace dr1715 { // dr1715: 3.9
11#if __cplusplus >= 201103L
12  struct B {
13    template<class T> B(T, typename T::Q);
14  };
15
16  class S {
17    using Q = int;
18    template<class T> friend B::B(T, typename T::Q);
19  };
20
21  struct D : B {
22    using B::B;
23  };
24  struct E : B { // expected-note 2{{candidate}}
25    template<class T> E(T t, typename T::Q q) : B(t, q) {} // expected-note {{'Q' is a private member}}
26  };
27
28  B b(S(), 1);
29  D d(S(), 2);
30  E e(S(), 3); // expected-error {{no match}}
31#endif
32}
33
34namespace dr1736 { // dr1736: 3.9
35#if __cplusplus >= 201103L
36struct S {
37  template <class T> S(T t) {
38    struct L : S {
39      using S::S;
40    };
41    typename T::type value; // expected-error {{no member}}
42    L l(value); // expected-note {{instantiation of}}
43  }
44};
45struct Q { typedef int type; } q;
46S s(q); // expected-note {{instantiation of}}
47#endif
48}
49
50namespace dr1756 { // dr1756: 3.7
51#if __cplusplus >= 201103L
52  // Direct-list-initialization of a non-class object
53  
54  int a{0};
55  
56  struct X { operator int(); } x;
57  int b{x};
58#endif
59}
60
61namespace dr1758 { // dr1758: 3.7
62#if __cplusplus >= 201103L
63  // Explicit conversion in copy/move list initialization
64
65  struct X { X(); };
66  struct Y { explicit operator X(); } y;
67  X x{y};
68
69  struct A {
70    A() {}
71    A(const A &) {}
72  };
73  struct B {
74    operator A() { return A(); }
75  } b;
76  A a{b};
77#endif
78}
79
80namespace dr1722 { // dr1722: 9.0
81#if __cplusplus >= 201103L
82void f() {
83  const auto lambda = [](int x) { return x + 1; };
84  // Without the DR applied, this static_assert would fail.
85  static_assert(
86      noexcept((int (*)(int))(lambda)),
87      "Lambda-to-function-pointer conversion is expected to be noexcept");
88}
89#endif
90} // namespace dr1722
91