brintos

brintos / llvm-project-archived public Read only

0
0
Text · 34.7 KiB · 8e3e49d Raw
722 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14,cxx14-17 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors8 9#if __cplusplus == 199711L10#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)11// cxx98-error@-1 {{variadic macros are a C99 feature}}12#endif13 14namespace cwg1512 { // cwg1512: 415  void f(char *p) {16    if (p > 0) {}17    // expected-error@-1 {{ordered comparison between pointer and zero ('char *' and 'int')}}18#if __cplusplus >= 201103L19    if (p > nullptr) {}20    // since-cxx11-error@-1 {{invalid operands to binary expression ('char *' and 'std::nullptr_t')}}21#endif22  }23  bool g(int **x, const int **y) {24    return x < y;25  }26 27  template<typename T> T val();28 29  template<typename A, typename B, typename C> void composite_pointer_type_is_base() {30    typedef __typeof(true ? val<A>() : val<B>()) type;31    typedef C type;32 33    typedef __typeof(val<A>() == val<B>()) cmp;34    typedef __typeof(val<A>() != val<B>()) cmp;35    typedef bool cmp;36  }37 38  template<typename A, typename B, typename C> void composite_pointer_type_is_ord() {39    composite_pointer_type_is_base<A, B, C>();40 41    typedef __typeof(val<A>() < val<B>()) cmp; // #cwg1512-lt42    // since-cxx17-warning@#cwg1512-lt {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}43    //   since-cxx17-note@#cwg1512-noexcept-1st {{in instantiation of function template specialization 'cwg1512::composite_pointer_type_is_ord<int (*)() noexcept, int (*)(), int (*)()>' requested here}}44    // since-cxx17-warning@#cwg1512-lt {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}45    //   since-cxx17-note@#cwg1512-noexcept-2nd {{in instantiation of function template specialization 'cwg1512::composite_pointer_type_is_ord<int (*)(), int (*)() noexcept, int (*)()>' requested here}}46    typedef __typeof(val<A>() <= val<B>()) cmp;47    // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}48    // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}49    typedef __typeof(val<A>() > val<B>()) cmp;50    // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}51    // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}52    typedef __typeof(val<A>() >= val<B>()) cmp;53    // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}54    // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}55    typedef bool cmp;56  }57 58  template <typename A, typename B, typename C>59  void composite_pointer_type_is_unord(int = 0) {60    composite_pointer_type_is_base<A, B, C>();61  }62  template <typename A, typename B, typename C>63  void composite_pointer_type_is_unord(__typeof(val<A>() < val<B>()) * = 0);64  template <typename A, typename B, typename C>65  void composite_pointer_type_is_unord(__typeof(val<A>() <= val<B>()) * = 0);66  template <typename A, typename B, typename C>67  void composite_pointer_type_is_unord(__typeof(val<A>() > val<B>()) * = 0);68  template <typename A, typename B, typename C>69  void composite_pointer_type_is_unord(__typeof(val<A>() >= val<B>()) * = 0);70 71  // A call to this is ambiguous if a composite pointer type exists.72  template<typename A, typename B>73  void no_composite_pointer_type(__typeof((true ? val<A>() : val<B>()), void()) * = 0);74  template<typename A, typename B> void no_composite_pointer_type(int = 0);75 76  struct A {};77  struct B : A {};78  struct C {};79 80  void test() {81#if __cplusplus >= 201103L82    using nullptr_t = decltype(nullptr);83    composite_pointer_type_is_unord<nullptr_t, nullptr_t, nullptr_t>();84    no_composite_pointer_type<nullptr_t, int>();85 86    composite_pointer_type_is_unord<nullptr_t, const char**, const char**>();87    composite_pointer_type_is_unord<const char**, nullptr_t, const char**>();88#endif89 90    composite_pointer_type_is_ord<const int *, volatile void *, const volatile void*>();91    composite_pointer_type_is_ord<const void *, volatile int *, const volatile void*>();92 93    composite_pointer_type_is_ord<const A*, volatile B*, const volatile A*>();94    composite_pointer_type_is_ord<const B*, volatile A*, const volatile A*>();95 96    composite_pointer_type_is_unord<const int *A::*, volatile int *B::*, const volatile int *const B::*>();97    composite_pointer_type_is_unord<const int *B::*, volatile int *A::*, const volatile int *const B::*>();98    no_composite_pointer_type<int (A::*)(), int (C::*)()>();99    no_composite_pointer_type<const int (A::*)(), volatile int (C::*)()>();100    // since-cxx20-warning@-1 {{volatile-qualified return type 'volatile int' is deprecated}}101 102#if __cplusplus >= 201703L103    composite_pointer_type_is_ord<int (*)() noexcept, int (*)(), int (*)()>(); // #cwg1512-noexcept-1st104    composite_pointer_type_is_ord<int (*)(), int (*)() noexcept, int (*)()>(); // #cwg1512-noexcept-2nd105    composite_pointer_type_is_unord<int (A::*)() noexcept, int (A::*)(), int (A::*)()>();106    composite_pointer_type_is_unord<int (A::*)(), int (A::*)() noexcept, int (A::*)()>();107    // FIXME: This looks like a standard defect; these should probably all have type 'int (B::*)()'.108    composite_pointer_type_is_unord<int (B::*)(), int (A::*)() noexcept, int (B::*)()>();109    composite_pointer_type_is_unord<int (A::*)() noexcept, int (B::*)(), int (B::*)()>();110    composite_pointer_type_is_unord<int (B::*)() noexcept, int (A::*)(), int (B::*)()>();111    composite_pointer_type_is_unord<int (A::*)(), int (B::*)() noexcept, int (B::*)()>();112 113    // FIXME: It would be reasonable to permit these, with a common type of 'int (*const *)()'.114    no_composite_pointer_type<int (**)() noexcept, int (**)()>();115    no_composite_pointer_type<int (**)(), int (**)() noexcept>();116 117    // FIXME: It would be reasonable to permit these, with a common type of 'int (A::*)()'.118    no_composite_pointer_type<int (A::*)() const, int (A::*)()>();119    no_composite_pointer_type<int (A::*)(), int (A::*)() const>();120 121    // FIXME: It would be reasonable to permit these, with a common type of122    // 'int (A::*)() &' and 'int (A::*)() &&', respectively.123    no_composite_pointer_type<int (A::*)() &, int (A::*)()>();124    no_composite_pointer_type<int (A::*)(), int (A::*)() &>();125    no_composite_pointer_type<int (A::*)() &&, int (A::*)()>();126    no_composite_pointer_type<int (A::*)(), int (A::*)() &&>();127 128    no_composite_pointer_type<int (A::*)() &&, int (A::*)() &>();129    no_composite_pointer_type<int (A::*)() &, int (A::*)() &&>();130 131    no_composite_pointer_type<int (C::*)(), int (A::*)() noexcept>();132    no_composite_pointer_type<int (A::*)() noexcept, int (C::*)()>();133#endif134  }135 136#if __cplusplus >= 201103L137  template<typename T> struct Wrap { operator T(); }; // #cwg1512-Wrap138  void test_overload() {139    using nullptr_t = decltype(nullptr);140    void(Wrap<nullptr_t>() == Wrap<nullptr_t>());141    void(Wrap<nullptr_t>() != Wrap<nullptr_t>());142    void(Wrap<nullptr_t>() < Wrap<nullptr_t>());143    // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}144    void(Wrap<nullptr_t>() > Wrap<nullptr_t>());145    // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}146    void(Wrap<nullptr_t>() <= Wrap<nullptr_t>());147    // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}148    void(Wrap<nullptr_t>() >= Wrap<nullptr_t>());149    // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}150 151    // Under cwg1213, this is ill-formed: we select the builtin operator<(int*, int*)152    // but then only convert as far as 'nullptr_t', which we then can't convert to 'int*'.153    void(Wrap<nullptr_t>() == Wrap<int*>());154    void(Wrap<nullptr_t>() != Wrap<int*>());155    void(Wrap<nullptr_t>() < Wrap<int*>());156    // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<int *>')}}157    //   since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}158    //   since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}159    void(Wrap<nullptr_t>() > Wrap<int*>());160    // since-cxx11-error@-1 {{invalid operands}}161    //   since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}162    //   since-cxx11-note@#cwg1512-Wrap{{second operand was implicitly converted to type 'int *'}}163    void(Wrap<nullptr_t>() <= Wrap<int*>());164    // since-cxx11-error@-1 {{invalid operands}}165    //   since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}166    //   since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}167    void(Wrap<nullptr_t>() >= Wrap<int*>());168    // since-cxx11-error@-1 {{invalid operands}}169    //   since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}170    //   since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}171  }172#endif173} // namespace cwg1512174 175namespace cwg1514 { // cwg1514: 11176#if __cplusplus >= 201103L177  struct S {178    enum E : int {}; // #cwg1514-E179    enum E : int {};180    // since-cxx11-error@-1 {{redefinition of 'E'}}181    //   since-cxx11-note@#cwg1514-E {{previous definition is here}}182  };183  S::E se; // OK, complete type, not zero-width bitfield.184 185  // The behavior in other contexts is superseded by CWG1966.186#endif187} // namespace cwg1514188 189namespace cwg1518 { // cwg1518: 4190#if __cplusplus >= 201103L191struct Z0 { // #cwg1518-Z0192  explicit Z0() = default; // #cwg1518-Z0-ctor193};194struct Z { // #cwg1518-Z195  explicit Z(); // #cwg1518-Z-ctor196  explicit Z(int); // #cwg1518-Z-int197  explicit Z(int, int); // #cwg1518-Z-int-int198};199template <class T> int Eat(T); // #cwg1518-Eat200Z0 a;201Z0 b{};202Z0 c = {};203// since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}204//   since-cxx11-note@#cwg1518-Z0-ctor {{explicit constructor declared here}}205int i = Eat<Z0>({});206// since-cxx11-error@-1 {{no matching function for call to 'Eat'}}207//   since-cxx11-note@#cwg1518-Eat {{candidate function template not viable: cannot convert initializer list argument to 'Z0'}}208 209Z c2 = {};210// since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}211//   since-cxx11-note@#cwg1518-Z-ctor {{explicit constructor declared here}}212int i2 = Eat<Z>({});213// since-cxx11-error@-1 {{no matching function for call to 'Eat'}}214//   since-cxx11-note@#cwg1518-Eat {{candidate function template not viable: cannot convert initializer list argument to 'Z'}}215Z a1 = 1;216// since-cxx11-error@-1 {{no viable conversion from 'int' to 'Z'}}217//   since-cxx11-note@#cwg1518-Z {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const Z &' for 1st argument}}218//   since-cxx11-note@#cwg1518-Z {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'Z &&' for 1st argument}}219//   since-cxx11-note@#cwg1518-Z-int {{explicit constructor is not a candidate}}220Z a3 = Z(1);221Z a2(1);222Z *p = new Z(1);223Z a4 = (Z)1;224Z a5 = static_cast<Z>(1);225Z a6 = {4, 3};226// since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}227//   since-cxx11-note@#cwg1518-Z-int-int {{explicit constructor declared here}}228 229struct UserProvidedBaseCtor { // #cwg1518-U230  UserProvidedBaseCtor() {}231};232struct DoesntInheritCtor : UserProvidedBaseCtor { // #cwg1518-D-U233  int x;234};235DoesntInheritCtor I{{}, 42};236// cxx11-14-error@-1 {{no matching constructor for initialization of 'DoesntInheritCtor'}}237//   cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}238//   cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}239//   cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided}}240 241struct BaseCtor { BaseCtor() = default; }; // #cwg1518-BC242struct InheritsCtor : BaseCtor { // #cwg1518-I243  using BaseCtor::BaseCtor;      // #cwg1518-I-using244  int x;245};246InheritsCtor II = {{}, 42};247// since-cxx11-error@-1 {{no matching constructor for initialization of 'InheritsCtor'}}248//   since-cxx11-note@#cwg1518-BC {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}249//   since-cxx11-note@#cwg1518-I-using {{constructor from base class 'BaseCtor' inherited here}}250//   since-cxx11-note@#cwg1518-BC {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}251//   since-cxx11-note@#cwg1518-I-using {{constructor from base class 'BaseCtor' inherited here}}252//   since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}253//   since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}254//   since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided}}255 256namespace std_example {257  struct A {258    explicit A() = default; // #cwg1518-A259  };260 261  struct B : A {262    explicit B() = default; // #cwg1518-B263  };264 265  struct C {266    explicit C(); // #cwg1518-C267  };268 269  struct D : A {270    C c;271    explicit D() = default; // #cwg1518-D272  };273 274  template <typename T> void f() {275    T t; // ok276    T u{}; // ok277    T v = {}; // #cwg1518-v278    // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}279    //   since-cxx11-note@#cwg1518-f-A {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::A>' requested here}}280    //   since-cxx11-note@#cwg1518-A {{explicit constructor declared here}}281    // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}282    //   since-cxx11-note@#cwg1518-f-B {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::B>' requested here}}283    //   since-cxx11-note@#cwg1518-B {{explicit constructor declared here}}284    // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}285    //   since-cxx11-note@#cwg1518-f-C {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::C>' requested here}}286    //   since-cxx11-note@#cwg1518-C {{explicit constructor declared here}}287    // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}288    //   since-cxx11-note@#cwg1518-f-D {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::D>' requested here}}289    //   since-cxx11-note@#cwg1518-D {{explicit constructor declared here}}290  }291  template <typename T> void g() {292    void x(T t); // #cwg1518-x293    x({}); // #cwg1518-x-call294    // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}295    //   since-cxx11-note@#cwg1518-g-A {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::A>' requested here}}296    //   since-cxx11-note@#cwg1518-A {{explicit constructor declared here}}297    //   since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}298    // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}299    //   since-cxx11-note@#cwg1518-g-B {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::B>' requested here}}300    //   since-cxx11-note@#cwg1518-B {{explicit constructor declared here}}301    //   since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}302    // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}303    //   since-cxx11-note@#cwg1518-g-C {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::C>' requested here}}304    //   since-cxx11-note@#cwg1518-C {{explicit constructor declared here}}305    //   since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}306    // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}307    //   since-cxx11-note@#cwg1518-g-D {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::D>' requested here}}308    //   since-cxx11-note@#cwg1518-D {{explicit constructor declared here}}309    //   since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}310  }311 312  void test() {313    f<A>(); // #cwg1518-f-A314    f<B>(); // #cwg1518-f-B315    f<C>(); // #cwg1518-f-C316    f<D>(); // #cwg1518-f-D317    g<A>(); // #cwg1518-g-A318    g<B>(); // #cwg1518-g-B319    g<C>(); // #cwg1518-g-C320    g<D>(); // #cwg1518-g-D321  }322}323#endif // __cplusplus >= 201103L324} // namespace cwg1518325 326namespace cwg1550 { // cwg1550: 3.4327  int f(bool b, int n) {328    return (b ? (throw 0) : n) + (b ? n : (throw 0));329  }330} // namespace cwg1550331 332namespace cwg1558 { // cwg1558: 12333#if __cplusplus >= 201103L334  template<class T, class...> using first_of = T;335  template<class T> first_of<void, typename T::type> f(int); // #cwg1558-f336  template<class T> void f(...) = delete; // #cwg1558-f-deleted337 338  struct X { typedef void type; };339  void test() {340    f<X>(0);341    f<int>(0);342    // since-cxx11-error@-1 {{call to deleted function 'f'}}343    //   since-cxx11-note@#cwg1558-f-deleted {{candidate function [with T = int] has been explicitly deleted}}344    //   since-cxx11-note@#cwg1558-f {{candidate template ignored: substitution failure [with T = int]: type 'int' cannot be used prior to '::' because it has no members}}345  }346#endif347} // namespace cwg1558348 349namespace cwg1560 { // cwg1560: 3.5350  void f(bool b, int n) {351    (b ? throw 0 : n) = (b ? n : throw 0) = 0;352  }353  class X { X(const X&); };354  const X &get();355  const X &x = true ? get() : throw 0;356} // namespace cwg1560357 358namespace cwg1563 { // cwg1563: 3.1359#if __cplusplus >= 201103L360  double bar(double) { return 0.0; }361  float bar(float) { return 0.0f; }362 363  using fun = double(double);364  fun &foo{bar}; // ok365#endif366} // namespace cwg1563367 368namespace cwg1567 { // cwg1567: 3.3369#if __cplusplus >= 201103L370struct B;371struct A {372  A(const A&);373  A(const B&) = delete;374  A(A&&);375  A(B&&) = delete;376  A(int); // #cwg1567-A-int377};378 379struct B: A { // #cwg1567-B380  using A::A; // #cwg1567-using-A381  B(double); // #cwg1567-B-double382};383 384A a{0};385B b{1.0};386// Good, deleted converting ctors are not inherited as copy/move ctors387B b2{b};388B b3{B{1.0}};389// Good, copy/move ctors are not inherited390B b4{a};391// since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}392//   since-cxx11-note@#cwg1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}393//   since-cxx11-note@#cwg1567-using-A {{constructor from base class 'A' inherited here}}394//   since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}395//   since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}396//   since-cxx11-note@#cwg1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}397B b5{A{0}};398// since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}399//   since-cxx11-note@#cwg1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}400//   since-cxx11-note@#cwg1567-using-A {{constructor from base class 'A' inherited here}}401//   since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}402//   since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}403//   since-cxx11-note@#cwg1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}404#endif405} // namespace cwg1567406 407namespace cwg1573 { // cwg1573: 3.9408#if __cplusplus >= 201103L409  // ellipsis is inherited (p0136r1 supersedes this part).410  struct A { A(); A(int, char, ...); };411  struct B : A { using A::A; };412  B b(1, 'x', 4.0, "hello"); // ok413 414  // inherited constructor is effectively constexpr if the user-written constructor would be415  struct C { C(); constexpr C(int) {} }; // #cwg1573-C416  struct D : C { using C::C; };417  constexpr D d = D(0); // ok418  struct E : C { using C::C; A a; }; // #cwg1573-E419  constexpr E e = E(0);420  // since-cxx11-error@-1 {{constexpr variable cannot have non-literal type 'const E'}}421  //   since-cxx11-note@#cwg1573-E {{'E' is not literal because it has data member 'a' of non-literal type 'A'}}422 423  // FIXME: This diagnostic is pretty bad; we should explain that the problem424  // is that F::c would be initialized by a non-constexpr constructor.425  struct F : C { using C::C; C c; }; // #cwg1573-F426  constexpr F f = F(0);427  // since-cxx11-error@-1 {{constexpr variable 'f' must be initialized by a constant expression}}428  //   cxx11-20-note@-2 {{constructor inherited from base class 'C' cannot be used in a constant expression; derived class cannot be implicitly initialized}}429  //   since-cxx23-note@-3 {{in implicit initialization for inherited constructor of 'F'}}430  //   since-cxx23-note@#cwg1573-F {{non-constexpr constructor 'C' cannot be used in a constant expression}}431  //   cxx11-20-note@#cwg1573-F {{declared here}}432  //   since-cxx23-note@#cwg1573-C {{declared here}}433 434  // inherited constructor is effectively deleted if the user-written constructor would be435  struct G { G(int); };436  struct H : G { using G::G; G g; }; // #cwg1573-H437  H h(0);438  // since-cxx11-error@-1 {{constructor inherited by 'H' from base class 'G' is implicitly deleted}}439  //   since-cxx11-note@#cwg1573-H {{constructor inherited by 'H' is implicitly deleted because field 'g' has no default constructor}}440 441  // deleted definition of constructor is inherited442  struct I { I(int) = delete; }; // #cwg1573-I443  struct J : I { using I::I; };444  J j(0);445  // since-cxx11-error@-1 {{call to deleted constructor of 'J'}}446  //   since-cxx11-note@#cwg1573-I {{'I' has been explicitly marked deleted here}}447#endif448} // namespace cwg1573449 450#if __cplusplus >= 201103L451namespace std {452  typedef decltype(sizeof(int)) size_t;453 454  // libc++'s implementation455  template <class _E>456  class initializer_list457  {458    const _E* __begin_;459    size_t    __size_;460 461    initializer_list(const _E* __b, size_t __s)462    : __begin_(__b), __size_(__s) {}463 464  public:465    typedef _E        value_type;466    typedef const _E& reference;467    typedef const _E& const_reference;468    typedef size_t    size_type;469 470    typedef const _E* iterator;471    typedef const _E* const_iterator;472 473    initializer_list() : __begin_(nullptr), __size_(0) {}474 475    size_t    size()  const {return __size_;}476    const _E* begin() const {return __begin_;}477    const _E* end()   const {return __begin_ + __size_;}478  };479 480  template < class _T1, class _T2 > struct pair { _T2 second; };481 482  template<typename T> struct basic_string {483    basic_string(const T* x) {}484    ~basic_string() {};485  };486  typedef basic_string<char> string;487 488} // namespace std489#endif490 491namespace cwg1579 { // cwg1579: 3.9492#if __cplusplus >= 201103L493template<class T>494struct GenericMoveOnly {495  GenericMoveOnly();496  template<class U> GenericMoveOnly(const GenericMoveOnly<U> &) = delete; // #cwg1579-deleted-U497  GenericMoveOnly(const int &) = delete; // #cwg1579-deleted-int498  template<class U> GenericMoveOnly(GenericMoveOnly<U> &&);499  GenericMoveOnly(int &&);500};501 502GenericMoveOnly<float> CWG1579_Eligible(GenericMoveOnly<char> CharMO) {503  int i;504  GenericMoveOnly<char> GMO;505 506  if (0)507    return i;508  else if (0)509    return GMO;510  else if (0)511    return ((GMO));512  else513    return CharMO;514}515 516GenericMoveOnly<char> GlobalMO;517 518GenericMoveOnly<float> CWG1579_Ineligible(int &AnInt,519                                          GenericMoveOnly<char> &CharMO) {520  static GenericMoveOnly<char> StaticMove;521  extern GenericMoveOnly<char> ExternMove;522 523  if (0)524    return AnInt;525    // since-cxx11-error@-1 {{conversion function from 'int' to 'GenericMoveOnly<float>' invokes a deleted function}}526    //   since-cxx11-note@#cwg1579-deleted-int {{'GenericMoveOnly' has been explicitly marked deleted here}}527  else if (0)528    return GlobalMO;529    // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}530    //   since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}531  else if (0)532    return StaticMove;533    // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}534    //   since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}535  else if (0)536    return ExternMove;537    // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}538    //   since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}539  else if (0)540    return AnInt;541    // since-cxx11-error@-1 {{conversion function from 'int' to 'GenericMoveOnly<float>' invokes a deleted function}}542    //   since-cxx11-note@#cwg1579-deleted-int {{'GenericMoveOnly' has been explicitly marked deleted here}}543  else544    return CharMO;545    // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}546    //   since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}547}548 549auto CWG1579_lambda_valid = [](GenericMoveOnly<float> mo) ->550  GenericMoveOnly<char> {551  return mo;552};553 554auto CWG1579_lambda_invalid = []() -> GenericMoveOnly<char> {555  static GenericMoveOnly<float> mo;556  return mo;557  // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<float>' to 'GenericMoveOnly<char>' invokes a deleted function}}558  //   since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<float>' has been explicitly marked deleted here}}559};560#endif561} // namespace cwg1579562 563namespace cwg1584 { // cwg1584: 7 drafting 2015-05564// Deducing function types from cv-qualified types565template<typename T> void f(const T *); // #cwg1584-f566template<typename T> void g(T *, const T * = 0);567template<typename T> void h(T *) { T::error; }568// expected-error@-1 {{type 'void ()' cannot be used prior to '::' because it has no members}}569//   expected-note@#cwg1584-h {{in instantiation of function template specialization 'cwg1584::h<void ()>' requested here}}570template<typename T> void h(const T *);571void i() {572  f(&i);573  // expected-error@-1 {{no matching function for call to 'f'}}574  //   expected-note@#cwg1584-f {{candidate template ignored: could not match 'const T *' against 'void (*)()'}}575  g(&i);576  h(&i); // #cwg1584-h577}578 579template<typename T> struct tuple_size {580  static const bool is_primary = true;581};582template<typename T> struct tuple_size<T const> : tuple_size<T> {583  static const bool is_primary = false;584};585 586tuple_size<void()> t;587static_assert(tuple_size<void()>::is_primary, "");588static_assert(tuple_size<void()const>::is_primary, "");589} // namespace cwg1584590 591namespace cwg1589 {   // cwg1589: 3.7 c++11592#if __cplusplus >= 201103L593  // Ambiguous ranking of list-initialization sequences594 595  void f0(long, int=0);                 // Would makes selection of #0 ambiguous596  void f0(long);                        // #0597  void f0(std::initializer_list<int>);  // #00598  void g0() { f0({1L}); }               // chooses #00599 600  void f1(int, int=0);                    // Would make selection of #1 ambiguous601  void f1(int);                           // #1602  void f1(std::initializer_list<long>);   // #2603  void g1() { f1({42}); }                 // chooses #2604 605  void f2(std::pair<const char*, const char*>, int = 0); // Would makes selection of #3 ambiguous606  void f2(std::pair<const char*, const char*>); // #3607  void f2(std::initializer_list<std::string>);  // #4608  void g2() { f2({"foo","bar"}); }              // chooses #4609 610  namespace with_error {611    void f0(long);612    void f0(std::initializer_list<int>);          // #cwg1589-f0-ilist613    void f0(std::initializer_list<int>, int = 0); // #cwg1589-f0-ilist-int614    void g0() { f0({1L}); }615    // since-cxx11-error@-1 {{call to 'f0' is ambiguous}}616    //   since-cxx11-note@#cwg1589-f0-ilist {{candidate function}}617    //   since-cxx11-note@#cwg1589-f0-ilist-int {{candidate function}}618 619    void f1(int);620    void f1(std::initializer_list<long>);          // #cwg1589-f1-ilist621    void f1(std::initializer_list<long>, int = 0); // #cwg1589-f1-ilist-long622    void g1() { f1({42}); }623    // since-cxx11-error@-1 {{call to 'f1' is ambiguous}}624    //   since-cxx11-note@#cwg1589-f1-ilist {{candidate function}}625    //   since-cxx11-note@#cwg1589-f1-ilist-long {{candidate function}}626 627    void f2(std::pair<const char*, const char*>);628    void f2(std::initializer_list<std::string>);          // #cwg1589-f2-ilist629    void f2(std::initializer_list<std::string>, int = 0); // #cwg1589-f2-ilist-int630    void g2() { f2({"foo","bar"}); }631    // since-cxx11-error@-1 {{call to 'f2' is ambiguous}}632    //   since-cxx11-note@#cwg1589-f2-ilist {{candidate function}}633    //   since-cxx11-note@#cwg1589-f2-ilist-int {{candidate function}}634  }635#endif636} // namespace cwg1589637 638namespace cwg1591 {  //cwg1591. Deducing array bound and element type from initializer list639#if __cplusplus >= 201103L640  template<class T, int N> int h(T const(&)[N]);641  int X = h({1,2,3});              // T deduced to int, N deduced to 3642 643  template<class T> int j(T const(&)[3]);644  int Y = j({42});                 // T deduced to int, array bound not considered645 646  struct Aggr { int i; int j; };647  template<int N> int k(Aggr const(&)[N]); // #cwg1591-k648  int Y0 = k({1,2,3});649  // since-cxx11-error@-1 {{no matching function for call to 'k'}}650  //   since-cxx11-note@#cwg1591-k {{candidate function [with N = 3] not viable: no known conversion from 'int' to 'const Aggr' for 1st argument}}651  int Z = k({{1},{2},{3}});        // OK, N deduced to 3652 653  template<int M, int N> int m(int const(&)[M][N]);654  int X0 = m({{1,2},{3,4}});        // M and N both deduced to 2655 656  template<class T, int N> int n(T const(&)[N], T);657  int X1 = n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3658 659 660  namespace check_multi_dim_arrays {661    template<class T, int N, int M, int O> int ***f(const T (&a)[N][M][O]); // #cwg1591-f-3662    template<class T, int N, int M> int **f(const T (&a)[N][M]); // #cwg1591-f-2663 664   template<class T, int N> int *f(const T (&a)[N]); // #cwg1591-f-1665    int ***p3 = f({  {  {1,2}, {3, 4}  }, {  {5,6}, {7, 8}  }, {  {9,10}, {11, 12}  } });666    int ***p33 = f({  {  {1,2}, {3, 4}  }, {  {5,6}, {7, 8}  }, {  {9,10}, {11, 12, 13}  } });667    // since-cxx11-error@-1 {{no matching function for call to 'f'}}668    //   since-cxx11-note@#cwg1591-f-2 {{candidate template ignored: couldn't infer template argument 'T'}}669    //   since-cxx11-note@#cwg1591-f-1 {{candidate template ignored: couldn't infer template argument 'T'}}670    //   since-cxx11-note@#cwg1591-f-3 {{candidate template ignored: deduced conflicting values for parameter 'O' (2 vs. 3)}}671    int **p2 = f({  {1,2,3}, {3, 4, 5}  });672    int **p22 = f({  {1,2}, {3, 4}  });673    int *p1 = f({1, 2, 3});674  }675  namespace check_multi_dim_arrays_rref {676    template<class T, int N, int M, int O> int ***g(T (&&a)[N][M][O]); // #cwg1591-g-3677    template<class T, int N, int M> int **g(T (&&a)[N][M]); // #cwg1591-g-2678 679    template<class T, int N> int *g(T (&&a)[N]); // #cwg1591-g-1680    int ***p3 = g({  {  {1,2}, {3, 4}  }, {  {5,6}, {7, 8}  }, {  {9,10}, {11, 12}  } });681    int ***p33 = g({  {  {1,2}, {3, 4}  }, {  {5,6}, {7, 8}  }, {  {9,10}, {11, 12, 13}  } });682    // since-cxx11-error@-1 {{no matching function for call to 'g'}}683    //   since-cxx11-note@#cwg1591-g-2 {{candidate template ignored: couldn't infer template argument 'T'}}684    //   since-cxx11-note@#cwg1591-g-1 {{candidate template ignored: couldn't infer template argument 'T'}}685    //   since-cxx11-note@#cwg1591-g-3 {{candidate template ignored: deduced conflicting values for parameter 'O' (2 vs. 3)}}686    int **p2 = g({  {1,2,3}, {3, 4, 5}  });687    int **p22 = g({  {1,2}, {3, 4}  });688    int *p1 = g({1, 2, 3});689  }690 691  namespace check_arrays_of_init_list {692    template<class T, int N> float *h(const std::initializer_list<T> (&)[N]);693    template<class T, int N> double *h(const T(&)[N]);694    double *p = h({1, 2, 3});695    float *fp = h({{1}, {1, 2}, {1, 2, 3}});696  }697  namespace core_reflector_28543 {698 699    template<class T, int N> int *i(T (&&)[N]);  // #1700    template<class T> char *i(std::initializer_list<T> &&);  // #2701    template<class T, int N, int M> int **i(T (&&)[N][M]); // #3 #cwg1591-i-2702    template<class T, int N> char **i(std::initializer_list<T> (&&)[N]); // #4 #cwg1591-i-1703 704    template<class T> short *i(T (&&)[2]);  // #5705 706    template<class T> using Arr = T[];707 708    char *pc = i({1, 2, 3}); // OK prefer #2 via 13.3.3.2 [over.ics.rank]709    char *pc2 = i({1, 2}); // #2 also710    int *pi = i(Arr<int>{1, 2, 3}); // OK prefer #1711 712    void *pv1 = i({ {1, 2, 3}, {4, 5, 6} }); // ambiguous btw 3 & 4713    // since-cxx11-error@-1 {{call to 'i' is ambiguous}}714    //   since-cxx11-note@#cwg1591-i-2 {{candidate function [with T = int, N = 2, M = 3]}}715    //   since-cxx11-note@#cwg1591-i-1 {{candidate function [with T = int, N = 2]}}716    char **pcc = i({ {1}, {2, 3} }); // OK #4717 718    short *ps = i(Arr<int>{1, 2});  // OK #5719  }720#endif721} // namespace cwg1591722