242 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors8 9namespace cwg1710 { // cwg1710: no10// FIXME: all of the following is well-formed11template <typename T> struct D1 : T::template B<int>::template C<int> {};12template <typename T> struct D2 : T::B<int>::template C<int> {};13// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}14template <typename T> struct D3 : T::template B<int>::C<int> {};15// expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}16template <typename T> struct D4 : T::B<int>::C<int> {};17// expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}18// expected-error@-2 {{use 'template' keyword to treat 'C' as a dependent template name}}19} // namespace cwg171020 21namespace cwg1715 { // cwg1715: 3.922#if __cplusplus >= 201103L23 struct B {24 template<class T> B(T, typename T::Q);25 };26 27 class S {28 using Q = int;29 template<class T> friend B::B(T, typename T::Q);30 };31 32 struct D : B {33 using B::B;34 };35 struct E : B { // #cwg1715-E36 template<class T> E(T t, typename T::Q q) : B(t, q) {} // #cwg1715-E-ctor37 };38 39 B b(S(), 1);40 D d(S(), 2);41 E e(S(), 3);42 // since-cxx11-error@-1 {{no matching constructor for initialization of 'E'}}43 // since-cxx11-note@#cwg1715-E-ctor {{candidate template ignored: substitution failure [with T = S]: 'Q' is a private member of 'cwg1715::S'}}44 // since-cxx11-note@#cwg1715-E {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}45 // since-cxx11-note@#cwg1715-E {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}46#endif47} // namespace cwg171548 49namespace cwg1719 { // cwg1719: 1950#if __cplusplus >= 201103L51struct CStruct {52 int one;53 int two;54};55 56struct CStruct2 {57 int one;58 int two;59};60 61struct CStructWithQualifiers {62 const int one;63 volatile int two;64};65 66static_assert(__is_layout_compatible(CStruct, const CStruct2), "");67static_assert(__is_layout_compatible(CStruct, volatile CStruct2), "");68static_assert(__is_layout_compatible(const CStruct, volatile CStruct2), "");69static_assert(__is_layout_compatible(int, const int), "");70static_assert(__is_layout_compatible(int, volatile int), "");71static_assert(__is_layout_compatible(const int, volatile int), "");72static_assert(__is_layout_compatible(CStruct, CStructWithQualifiers), "");73static_assert(__is_layout_compatible(int[], const volatile int[]), "");74#endif75} // namespace cwg171976 77namespace cwg1722 { // cwg1722: 978#if __cplusplus >= 201103L79void f() {80 const auto lambda = [](int x) { return x + 1; };81 // Without the DR applied, this static_assert would fail.82 static_assert(83 noexcept((int (*)(int))(lambda)),84 "Lambda-to-function-pointer conversion is expected to be noexcept");85}86#endif87} // namespace cwg172288 89namespace cwg1734 { // cwg1734: no90#if __cplusplus >= 201103L91struct A {92 A(const A&) = delete;93};94// FIXME: 'A' should not be trivially copyable because the class lacks at least95// one non-deleted copy constructor, move constructor, copy assignment96// operator, or move assignment operator.97static_assert(__is_trivially_copyable(A), "");98#endif99} // namespace cwg1734100 101namespace cwg1736 { // cwg1736: 3.9102#if __cplusplus >= 201103L103struct S {104 template <class T> S(T t) {105 struct L : S {106 using S::S;107 };108 typename T::type value;109 // since-cxx11-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}110 // since-cxx11-note@#cwg1736-l {{in instantiation of function template specialization 'cwg1736::S::S<int>' requested here}}111 // since-cxx11-note@#cwg1736-s {{in instantiation of function template specialization 'cwg1736::S::S<cwg1736::Q>' requested here}}112 L l(value); // #cwg1736-l113 }114};115struct Q { typedef int type; } q;116S s(q); // #cwg1736-s117#endif118} // namespace cwg1736119 120namespace cwg1738 { // cwg1738: sup P0136R1121#if __cplusplus >= 201103L122struct A {123 template <typename T>124 A(int, T) {}125};126 127struct B : A {128 using A::A;129};130 131// FIXME: this is well-formed since P0136R1132template B::B(int, double);133// since-cxx11-error@-1 {{explicit instantiation of 'B' does not refer to a function template, variable template, member function, member class, or static data member}}134#endif135} // namespace cwg1738136 137// cwg1748 is in cwg1748.cpp138 139namespace cwg1753 { // cwg1753: 11140 typedef int T;141 struct A { typedef int T; };142 namespace B { typedef int T; }143 144 void f(T n) {145 n.~T();146 n.T::~T();147 148 n.cwg1753::~T();149 // expected-error@-1 {{'cwg1753' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T' (aka 'int')}}150 n.cwg1753::T::~T();151 152 n.A::~T();153 // expected-error@-1 {{the type of object expression ('T' (aka 'int')) does not match the type being destroyed ('A') in pseudo-destructor expression}}154 n.A::T::~T();155 156 n.B::~T();157 // expected-error@-1 {{'B' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T' (aka 'int')}}158 n.B::T::~T();159 160 #if __cplusplus >= 201103L161 n.decltype(n)::~T();162 // since-cxx11-error@-1 {{'decltype(n)' (aka 'int') is not a class, namespace, or enumeration}}163 n.T::~decltype(n)();164 // since-cxx11-error@-1 {{expected a class name after '~' to name a destructor}}165 n.~decltype(n)(); // OK166 #endif167 }168} // namespace cwg1753169 170namespace cwg1756 { // cwg1756: 3.7171#if __cplusplus >= 201103L172 // Direct-list-initialization of a non-class object173 174 int a{0};175 176 struct X { operator int(); } x;177 int b{x};178#endif179} // namespace cwg1756180 181namespace cwg1758 { // cwg1758: 3.7182#if __cplusplus >= 201103L183 // Explicit conversion in copy/move list initialization184 185 struct X { X(); };186 struct Y { explicit operator X(); } y;187 X x{y};188 189 struct A {190 A() {}191 A(const A &) {}192 };193 struct B {194 operator A() { return A(); }195 } b;196 A a{b};197#endif198} // namespace cwg1758199 200namespace cwg1762 { // cwg1762: 14201#if __cplusplus >= 201103L202 float operator ""_E(const char *);203 float operator ""E(const char *);204 // since-cxx11-error@-1 {{invalid suffix on literal; C++11 requires a space between literal and identifier}}205 // since-cxx11-warning@-2 {{user-defined literal suffixes not starting with '_' are reserved; no literal will invoke this operator}}206#endif207} // namespace cwg1762208 209// cwg1772 is in cwg177x.cpp210 211namespace cwg1778 { // cwg1778: 9212 // Superseded by P1286R2.213#if __cplusplus >= 201103L214 struct A { A() noexcept(true) = default; };215 struct B { B() noexcept(false) = default; };216 static_assert(noexcept(A()), "");217 static_assert(!noexcept(B()), "");218 219 struct C { A a; C() noexcept(false) = default; };220 struct D { B b; D() noexcept(true) = default; };221 static_assert(!noexcept(C()), "");222 static_assert(noexcept(D()), "");223#endif224} // namespace cwg1778225 226// cwg1779 is in cwg177x.cpp227 228namespace cwg1794 { // cwg1794: 2.7229 // NB: dup 1710230#if __cplusplus >= 201103L231template <template <typename> class Template> struct Internal {232 template <typename Arg> using Bind = Template<Arg>;233};234 235template <template <typename> class Template, typename Arg>236using Instantiate = Template<Arg>;237 238template <template <typename> class Template, typename Argument>239using Bind = Instantiate<Internal<Template>::template Bind, Argument>;240#endif241} // namespace cwg1794242