diff --git a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp --- a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp +++ b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp @@ -1,7 +1,8 @@ -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected,cxx20 %s -// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s -// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s -// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_14_17 %s +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -verify=expected,cxx20_2b %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=expected,cxx20_2b %s +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=expected,cxx11_17 %s namespace test_delete_function { struct A1 { @@ -54,38 +55,38 @@ namespace test_implicitly_movable_rvalue_ref { struct A1 { A1(A1 &&); - A1(const A1 &) = delete; // cxx11_14_17-note {{'A1' has been explicitly marked deleted here}} + A1(const A1 &) = delete; // cxx11_17-note {{'A1' has been explicitly marked deleted here}} }; A1 test1(A1 &&a) { - return a; // cxx11_14_17-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::A1'}} + return a; // cxx11_17-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::A1'}} } struct A2 { A2(A2 &&); private: - A2(const A2 &); // cxx11_14_17-note {{declared private here}} + A2(const A2 &); // cxx11_17-note {{declared private here}} }; A2 test2(A2 &&a) { - return a; // cxx11_14_17-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::A2'}} + return a; // cxx11_17-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::A2'}} } struct B1 { B1(const B1 &); - B1(B1 &&) = delete; // cxx20-note {{'B1' has been explicitly marked deleted here}} + B1(B1 &&) = delete; // cxx20_2b-note {{'B1' has been explicitly marked deleted here}} }; B1 test3(B1 &&b) { - return b; // cxx20-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::B1'}} + return b; // cxx20_2b-error {{call to deleted constructor of 'test_implicitly_movable_rvalue_ref::B1'}} } struct B2 { B2(const B2 &); private: - B2(B2 &&); // cxx20-note {{declared private here}} + B2(B2 &&); // cxx20_2b-note {{declared private here}} }; B2 test4(B2 &&b) { - return b; // cxx20-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::B2'}} + return b; // cxx20_2b-error {{calling a private constructor of class 'test_implicitly_movable_rvalue_ref::B2'}} } } // namespace test_implicitly_movable_rvalue_ref @@ -96,13 +97,14 @@ struct A1 { A1(const A1 &); - A1(A1 &&) = delete; // cxx20-note {{'A1' has been explicitly marked deleted here}} + A1(A1 &&) = delete; // cxx20_2b-note {{'A1' has been explicitly marked deleted here}} + // expected-note@-1 {{'A1' has been explicitly marked deleted here}} }; void test1() { try { func(); } catch (A1 a) { - throw a; // cxx20-error {{call to deleted constructor of 'test_throw_parameter::A1'}} + throw a; // cxx20_2b-error {{call to deleted constructor of 'test_throw_parameter::A1'}} } } @@ -110,15 +112,21 @@ A2(const A2 &); private: - A2(A2 &&); // cxx20-note {{declared private here}} + A2(A2 &&); // cxx20_2b-note {{declared private here}} }; void test2() { try { func(); } catch (A2 a) { - throw a; // cxx20-error {{calling a private constructor of class 'test_throw_parameter::A2'}} + throw a; // cxx20_2b-error {{calling a private constructor of class 'test_throw_parameter::A2'}} } } + +void test3(A1 a) try { + func(); +} catch (...) { + throw a; // expected-error {{call to deleted constructor of 'test_throw_parameter::A1'}} +} } // namespace test_throw_parameter // In C++20, during the first overload resolution, the selected function no @@ -128,42 +136,42 @@ struct A1 { operator C() &&; - operator C() const & = delete; // cxx11_14_17-note {{'operator C' has been explicitly marked deleted here}} + operator C() const & = delete; // cxx11_17-note {{'operator C' has been explicitly marked deleted here}} }; C test1() { A1 a; - return a; // cxx11_14_17-error {{conversion function from 'test_non_ctor_conversion::A1' to 'test_non_ctor_conversion::C' invokes a deleted function}} + return a; // cxx11_17-error {{conversion function from 'test_non_ctor_conversion::A1' to 'test_non_ctor_conversion::C' invokes a deleted function}} } struct A2 { operator C() &&; private: - operator C() const &; // cxx11_14_17-note {{declared private here}} + operator C() const &; // cxx11_17-note {{declared private here}} }; C test2() { A2 a; - return a; // cxx11_14_17-error {{'operator C' is a private member of 'test_non_ctor_conversion::A2'}} + return a; // cxx11_17-error {{'operator C' is a private member of 'test_non_ctor_conversion::A2'}} } struct B1 { operator C() const &; - operator C() && = delete; // cxx20-note {{'operator C' has been explicitly marked deleted here}} + operator C() && = delete; // cxx20_2b-note {{'operator C' has been explicitly marked deleted here}} }; C test3() { B1 b; - return b; // cxx20-error {{conversion function from 'test_non_ctor_conversion::B1' to 'test_non_ctor_conversion::C' invokes a deleted function}} + return b; // cxx20_2b-error {{conversion function from 'test_non_ctor_conversion::B1' to 'test_non_ctor_conversion::C' invokes a deleted function}} } struct B2 { operator C() const &; private: - operator C() &&; // cxx20-note {{declared private here}} + operator C() &&; // cxx20_2b-note {{declared private here}} }; C test4() { B2 b; - return b; // cxx20-error {{'operator C' is a private member of 'test_non_ctor_conversion::B2'}} + return b; // cxx20_2b-error {{'operator C' is a private member of 'test_non_ctor_conversion::B2'}} } } // namespace test_non_ctor_conversion @@ -182,35 +190,35 @@ NeedRvalueRef(B2 &&); }; struct NeedValue { - NeedValue(A1); // cxx11_14_17-note 2 {{passing argument to parameter here}} + NeedValue(A1); // cxx11_17-note 2 {{passing argument to parameter here}} NeedValue(A2); - NeedValue(B1); // cxx20-note 2 {{passing argument to parameter here}} + NeedValue(B1); // cxx20_2b-note 2 {{passing argument to parameter here}} NeedValue(B2); }; struct A1 { A1(); A1(A1 &&); - A1(const A1 &) = delete; // cxx11_14_17-note 3 {{'A1' has been explicitly marked deleted here}} + A1(const A1 &) = delete; // cxx11_17-note 3 {{'A1' has been explicitly marked deleted here}} }; NeedValue test_1_1() { // not rvalue reference // same type A1 a; - return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} + return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} } class DerivedA1 : public A1 {}; A1 test_1_2() { // rvalue reference // not same type DerivedA1 a; - return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} + return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} } NeedValue test_1_3() { // not rvalue reference // not same type DerivedA1 a; - return a; // cxx11_14_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} + return a; // cxx11_17-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::A1'}} } struct A2 { @@ -218,51 +226,51 @@ A2(A2 &&); private: - A2(const A2 &); // cxx11_14_17-note 3 {{declared private here}} + A2(const A2 &); // cxx11_17-note 3 {{declared private here}} }; NeedValue test_2_1() { // not rvalue reference // same type A2 a; - return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} + return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} } class DerivedA2 : public A2 {}; A2 test_2_2() { // rvalue reference // not same type DerivedA2 a; - return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} + return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} } NeedValue test_2_3() { // not rvalue reference // not same type DerivedA2 a; - return a; // cxx11_14_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} + return a; // cxx11_17-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::A2'}} } struct B1 { B1(); B1(const B1 &); - B1(B1 &&) = delete; // cxx20-note 3 {{'B1' has been explicitly marked deleted here}} + B1(B1 &&) = delete; // cxx20_2b-note 3 {{'B1' has been explicitly marked deleted here}} }; NeedValue test_3_1() { // not rvalue reference // same type B1 b; - return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} + return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} } class DerivedB1 : public B1 {}; B1 test_3_2() { // rvalue reference // not same type DerivedB1 b; - return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} + return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} } NeedValue test_3_3() { // not rvalue reference // not same type DerivedB1 b; - return b; // cxx20-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} + return b; // cxx20_2b-error {{call to deleted constructor of 'test_ctor_param_rvalue_ref::B1'}} } struct B2 { @@ -270,26 +278,26 @@ B2(const B2 &); private: - B2(B2 &&); // cxx20-note 3 {{declared private here}} + B2(B2 &&); // cxx20_2b-note 3 {{declared private here}} }; NeedValue test_4_1() { // not rvalue reference // same type B2 b; - return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} + return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} } class DerivedB2 : public B2 {}; B2 test_4_2() { // rvalue reference // not same type DerivedB2 b; - return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} + return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} } NeedValue test_4_3() { // not rvalue reference // not same type DerivedB2 b; - return b; // cxx20-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} + return b; // cxx20_2b-error {{calling a private constructor of class 'test_ctor_param_rvalue_ref::B2'}} } } // namespace test_ctor_param_rvalue_ref @@ -298,21 +306,21 @@ struct Target {}; // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable}} // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}} - // cxx11_14_17-note@-3 {{candidate constructor (the implicit copy constructor) not viable}} - // cxx11_14_17-note@-4 {{candidate constructor (the implicit move constructor) not viable}} + // cxx11_17-note@-3 {{candidate constructor (the implicit copy constructor) not viable}} + // cxx11_17-note@-4 {{candidate constructor (the implicit move constructor) not viable}} struct CopyOnly { - CopyOnly(CopyOnly&&) = delete; // cxx20-note {{has been explicitly marked deleted here}} + CopyOnly(CopyOnly&&) = delete; // cxx20_2b-note {{has been explicitly marked deleted here}} CopyOnly(CopyOnly&); - operator Target() && = delete; // cxx20-note {{has been explicitly marked deleted here}} + operator Target() && = delete; // cxx20_2b-note {{has been explicitly marked deleted here}} operator Target() &; }; struct MoveOnly { MoveOnly(MoveOnly&&); // expected-note {{copy constructor is implicitly deleted because}} - // cxx11_14_17-note@-1 {{copy constructor is implicitly deleted because}} + // cxx11_17-note@-1 {{copy constructor is implicitly deleted because}} operator Target() &&; // expected-note {{candidate function not viable}} - // cxx11_14_17-note@-1 {{candidate function not viable}} + // cxx11_17-note@-1 {{candidate function not viable}} }; extern CopyOnly copyonly; @@ -325,7 +333,7 @@ CopyOnly t2() { CopyOnly&& r = static_cast(copyonly); - return r; // cxx20-error {{call to deleted constructor}} + return r; // cxx20_2b-error {{call to deleted constructor}} } MoveOnly t3() { @@ -335,7 +343,7 @@ MoveOnly t4() { MoveOnly&& r = static_cast(moveonly); - return r; // cxx11_14_17-error {{call to implicitly-deleted copy constructor}} + return r; // cxx11_17-error {{call to implicitly-deleted copy constructor}} } Target t5() { @@ -345,7 +353,7 @@ Target t6() { CopyOnly&& r = static_cast(copyonly); - return r; // cxx20-error {{invokes a deleted function}} + return r; // cxx20_2b-error {{invokes a deleted function}} } Target t7() { @@ -355,7 +363,7 @@ Target t8() { MoveOnly&& r = static_cast(moveonly); - return r; // cxx11_14_17-error {{no viable conversion}} + return r; // cxx11_17-error {{no viable conversion}} } } // namespace test_lvalue_ref_is_not_moved_from @@ -397,3 +405,46 @@ } } // namespace test_rvalue_ref_to_nonobject + +namespace test_simpler_implicit_move { + +struct CopyOnly { + CopyOnly(); + CopyOnly(CopyOnly &); +}; +struct MoveOnly { + MoveOnly(); + MoveOnly(MoveOnly &&); +}; +MoveOnly &&rref(); + +MoveOnly &&test1(MoveOnly &&w) { + return w; // expected-error {{cannot bind to lvalue of type}} +} + +CopyOnly test2(bool b) { + static CopyOnly w1; + CopyOnly w2; + if (b) { + return w1; + } else { + return w2; + } +} + +template T &&test3(T &&x) { return x; } // expected-error {{cannot bind to lvalue of type}} +template MoveOnly& test3(MoveOnly&); +template MoveOnly&& test3(MoveOnly&&); // expected-note {{in instantiation of function template specialization}} + +MoveOnly &&test4() { + MoveOnly &&x = rref(); + return x; // expected-error {{cannot bind to lvalue of type}} +} + +void test5() try { + CopyOnly x; + throw x; +} catch (...) { +} + +} // namespace test_simpler_implicit_move diff --git a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp rename from clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp rename to clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp --- a/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp +++ b/clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -verify -std=c++1y %s +// RUN: %clang_cc1 -verify -std=c++2b -verify %s +// RUN: %clang_cc1 -verify -std=c++20 -verify %s +// RUN: %clang_cc1 -verify -std=c++14 -verify %s namespace std { template struct initializer_list { diff --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp --- a/clang/test/CXX/drs/dr3xx.cpp +++ b/clang/test/CXX/drs/dr3xx.cpp @@ -1,7 +1,9 @@ -// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++2b -verify=expected,cxx20_2b -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++20 -verify=expected,cxx20_2b -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors +// RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors namespace dr300 { // dr300: yes template void f(R (&)(A)) {} @@ -18,8 +20,8 @@ void f() { bool a = (void(*)(S, S))operator+ < (void(*)(S, S))operator+; - bool b = (void(*)(S, S))operator- < - (void(*)(S, S))operator-; + bool b = (void(*)(S, S))operator- < // cxx20_2b-note {{to match this '<'}} + (void(*)(S, S))operator-; // cxx20_2b-error {{expected '>'}} bool c = (void(*)(S, S))operator+ < // expected-note {{to match this '<'}} (void(*)(S, S))operator-; // expected-error {{expected '>'}} } @@ -439,8 +441,10 @@ namespace dr332 { // dr332: dup 577 void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}} + // cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}} void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}} void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}} + // cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}} } namespace dr333 { // dr333: yes @@ -910,10 +914,13 @@ namespace dr368 { // dr368: yes template struct S {}; // expected-note {{here}} template int f(S *); // expected-error {{function type}} - template int g(S *); // expected-note {{type 'dr368::X'}} - template int g(S *); // expected-note {{type 'dr368::X'}} + template int g(S *); // cxx98_17-note {{type 'dr368::X'}} + // cxx20_2b-note@-1 {{candidate function [with T = dr368::X]}} + template int g(S *); // cxx98_17-note {{type 'dr368::X'}} + // cxx20_2b-note@-1 {{candidate function [with T = dr368::X]}} struct X {}; - int n = g(0); // expected-error {{no matching}} + int n = g(0); // cxx98_17-error {{no matching}} + // cxx20_2b-error@-1 {{call to 'g' is ambiguous}} } // dr370: na @@ -1103,7 +1110,7 @@ } namespace dr385 { // dr385: yes - struct A { protected: void f(); }; + struct A { protected: void f(); }; struct B : A { using A::f; }; struct C : A { void g(B b) { b.f(); } }; void h(B b) { b.f(); } diff --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp rename from clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp rename to clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp --- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp +++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++1y %s -verify +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify %s int a; int &b = [] (int &r) -> decltype(auto) { return r; } (a); @@ -8,8 +10,7 @@ int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error {{cannot bind to a temporary}} int &g = [] (int r) -> decltype(auto) { return (r); } (a); // expected-warning {{reference to stack}} - -int test_explicit_auto_return() +int test_explicit_auto_return() { struct X {}; auto L = [](auto F, auto a) { return F(a); }; @@ -18,32 +19,32 @@ auto MPtr = [](auto c) -> auto* { return &c; }; //expected-warning{{address of stack}} auto MDeclType = [](auto&& d) -> decltype(auto) { return static_cast(d); }; //OK M(3); - + auto &&x = MDeclType(X{}); auto &&x1 = M(X{}); auto &&x2 = MRef(X{});//expected-note{{in instantiation of}} auto &&x3 = MPtr(X{}); //expected-note{{in instantiation of}} - return 0; + return 0; } -int test_implicit_auto_return() -{ +int test_implicit_auto_return() +{ { auto M = [](auto a) { return a; }; struct X {}; X x = M(X{}); - + } } - + int test_multiple_returns() { - auto M = [](auto a) { + auto M = [](auto a) { bool k; if (k) return a; else return 5; //expected-error{{deduced as 'int' here}} - }; + }; M(3); // OK M('a'); //expected-note{{in instantiation of}} return 0; @@ -57,10 +58,10 @@ } int test_conditional_in_return() { - auto Fac = [](auto f, auto n) { + auto Fac = [](auto f, auto n) { return n <= 0 ? n : f(f, n - 1) * n; }; // FIXME: this test causes a recursive limit - need to error more gracefully. //Fac(Fac, 3); -} \ No newline at end of file +} diff --git a/clang/test/CXX/special/class.copy/p33-0x.cpp b/clang/test/CXX/special/class.copy/p3-cxx11.cpp rename from clang/test/CXX/special/class.copy/p33-0x.cpp rename to clang/test/CXX/special/class.copy/p3-cxx11.cpp --- a/clang/test/CXX/special/class.copy/p33-0x.cpp +++ b/clang/test/CXX/special/class.copy/p3-cxx11.cpp @@ -1,3 +1,5 @@ +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++2b -fsyntax-only -verify %s +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++20 -fsyntax-only -verify %s // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -std=c++11 -fsyntax-only -verify %s class X { X(const X&); diff --git a/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp b/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp --- a/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp @@ -1,15 +1,18 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -struct A { +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s + +struct A { template operator T*(); -}; +}; template A::operator T*() { return 0; } template <> A::operator char*(){ return 0; } // specialization template A::operator void*(); // explicit instantiation -int main() { +int main() { A a; - int *ip; + int *ip; ip = a.operator int*(); } @@ -33,7 +36,7 @@ class Foo { public: template operator T(); - + template T As() { return this->operator T(); @@ -43,7 +46,7 @@ T As2() { return operator T(); } - + int AsInt() { return this->operator int(); } @@ -58,9 +61,9 @@ T x = 1; // expected-note{{variable 'x' declared const here}} x = 17; // expected-error{{cannot assign to variable 'x' with const-qualified type 'const int'}} } - + template operator T*() const; // expected-note{{explicit instantiation refers here}} - + template operator const T*() const { T x = T(); return x; // expected-error{{cannot initialize return object of type 'const char *' with an lvalue of type 'char'}} \ diff --git a/clang/test/SemaCXX/P1155.cpp b/clang/test/SemaCXX/P1155.cpp --- a/clang/test/SemaCXX/P1155.cpp +++ b/clang/test/SemaCXX/P1155.cpp @@ -1,8 +1,9 @@ -// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=cxx20 %s +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions -verify=cxx20_2b %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions -verify=cxx20_2b %s // RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s // RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=cxx11_14_17 %s -// cxx20-no-diagnostics +// cxx20_2b-no-diagnostics // Throwing namespace test_throwing { diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp b/clang/test/SemaCXX/constant-expression-cxx11.cpp --- a/clang/test/SemaCXX/constant-expression-cxx11.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp @@ -1,9 +1,12 @@ -// RUN: %clang_cc1 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fsyntax-only -fcxx-exceptions -verify -std=c++11 -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx20_2b -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx20_2b -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11 -triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith -Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s -Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion namespace StaticAssertFoldTest { int x; static_assert(++x, "test"); // expected-error {{not an integral constant expression}} +// cxx20_2b-note@-1 {{cannot modify an object that is visible outside that expression}} static_assert(false, "test"); // expected-error {{test}} } @@ -318,13 +321,13 @@ static_assert(&x > &x, "false"); // expected-error {{false}} constexpr S* sptr = &s; -constexpr bool dyncast = sptr == dynamic_cast(sptr); // expected-error {{constant expression}} expected-note {{dynamic_cast}} +constexpr bool dyncast = sptr == dynamic_cast(sptr); // cxx11-error {{constant expression}} cxx11-note {{dynamic_cast}} struct U {}; struct Str { int a : dynamic_cast(sptr) == dynamic_cast(sptr); // \ - expected-warning {{not an integral constant expression}} \ - expected-note {{dynamic_cast is not allowed in a constant expression}} + cxx11-warning {{not an integral constant expression}} \ + cxx11-note {{dynamic_cast is not allowed in a constant expression}} int b : reinterpret_cast(sptr) == reinterpret_cast(sptr); // \ expected-warning {{not an integral constant expression}} \ expected-note {{reinterpret_cast is not allowed in a constant expression}} @@ -348,6 +351,7 @@ extern char externalvar[]; constexpr bool constaddress = (void *)externalvar == (void *)0x4000UL; // expected-error {{must be initialized by a constant expression}} expected-note {{reinterpret_cast}} constexpr bool litaddress = "foo" == "foo"; // expected-error {{must be initialized by a constant expression}} +// cxx20_2b-warning@-1 {{comparison between two arrays is deprecated}} static_assert(0 != "foo", ""); } @@ -387,7 +391,7 @@ static_assert(&b4 != &b2, ""); // Proposed DR: copy-elision doesn't trigger lifetime extension. -// expected-warning@+1 2{{temporary whose address is used as value of local variable 'b5' will be destroyed at the end of the full-expression}} +// cxx11-warning@+1 2{{temporary whose address is used as value of local variable 'b5' will be destroyed at the end of the full-expression}} constexpr B b5 = B{ {0}, {0} }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}} namespace NestedNonStatic { @@ -397,8 +401,8 @@ struct A { int &&r; }; struct B { A &&a; }; constexpr B a = { A{0} }; // ok - // expected-warning@+1 {{temporary bound to reference member of local variable 'b' will be destroyed at the end of the full-expression}} - constexpr B b = { A(A{0}) }; // expected-error {{constant expression}} expected-note {{reference to temporary}} expected-note {{here}} + // cxx11-warning@+1 {{temporary bound to reference member of local variable 'b' will be destroyed at the end of the full-expression}} + constexpr B b = { A(A{0}) }; // cxx11-error {{constant expression}} cxx11-note {{reference to temporary}} cxx11-note {{here}} } namespace FakeInitList { @@ -1637,7 +1641,7 @@ namespace NamespaceAlias { constexpr int f() { - namespace NS = NamespaceAlias; // expected-warning {{use of this statement in a constexpr function is a C++14 extension}} + namespace NS = NamespaceAlias; // cxx11-warning {{use of this statement in a constexpr function is a C++14 extension}} return &NS::f != nullptr; } } @@ -1737,7 +1741,7 @@ } namespace Void { - constexpr void f() { return; } // expected-error{{constexpr function's return type 'void' is not a literal type}} + constexpr void f() { return; } // cxx11-error{{constexpr function's return type 'void' is not a literal type}} void assert_failed(const char *msg, const char *file, int line); // expected-note {{declared here}} #define ASSERT(expr) ((expr) ? static_cast(0) : assert_failed(#expr, __FILE__, __LINE__)) @@ -1759,11 +1763,12 @@ namespace TypeId { struct A { virtual ~A(); }; A f(); - A &g(); + A &g(); // cxx20_2b-note {{declared here}} constexpr auto &x = typeid(f()); - constexpr auto &y = typeid(g()); // expected-error{{constant expression}} \ - // expected-note{{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} \ - // expected-warning {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} + constexpr auto &y = typeid(g()); // expected-error{{constant expression}} + // cxx11-note@-1 {{typeid applied to expression of polymorphic type 'TypeId::A' is not allowed in a constant expression}} + // expected-warning@-2 {{expression with side effects will be evaluated despite being used as an operand to 'typeid'}} + // cxx20_2b-note@-3 {{non-constexpr function 'g' cannot be used in a constant expression}} } namespace PR14203 { @@ -1893,18 +1898,19 @@ template struct X : T { constexpr X() {} double d = 0.0; - constexpr int f() { return sizeof(T); } // expected-warning {{will not be implicitly 'const' in C++14}} + constexpr int f() { return sizeof(T); } // cxx11-warning {{will not be implicitly 'const' in C++14}} }; // Virtual f(), not OK. constexpr X> xxs1; constexpr X *p = const_cast>*>(&xxs1); - static_assert(p->f() == sizeof(X), ""); // expected-error {{constant expression}} expected-note {{virtual function}} + static_assert(p->f() == sizeof(X), ""); // cxx11-error {{constant expression}} cxx11-note {{virtual function}} + // cxx20_2b-error@-1 {{static_assert failed}} // Non-virtual f(), OK. constexpr X> xxs2; constexpr X *q = const_cast>*>(&xxs2); - static_assert(q->f() == sizeof(S2), ""); + static_assert(q->f() == sizeof(S2), ""); // cxx20_2b-error {{static_assert failed}} } namespace ConstexprConstructorRecovery { @@ -1917,10 +1923,10 @@ }; constexpr X() noexcept {}; protected: - E val{0}; // expected-error {{cannot initialize a member subobject of type 'ConstexprConstructorRecovery::X::E' with an rvalue of type 'int'}} expected-note {{here}} + E val{0}; // cxx11-error {{cannot initialize a member subobject of type 'ConstexprConstructorRecovery::X::E' with an rvalue of type 'int'}} cxx11-note {{here}} }; // FIXME: We should avoid issuing this follow-on diagnostic. - constexpr X x{}; // expected-error {{constant expression}} expected-note {{not initialized}} + constexpr X x{}; // cxx11-error {{constant expression}} cxx11-note {{not initialized}} } namespace Lifetime { @@ -2198,7 +2204,7 @@ struct InvalidRedef { int f; // expected-note{{previous definition is here}} - constexpr int f(void); // expected-error{{redefinition of 'f'}} expected-warning{{will not be implicitly 'const'}} + constexpr int f(void); // expected-error{{redefinition of 'f'}} cxx11-warning{{will not be implicitly 'const'}} }; namespace PR17938 { @@ -2243,21 +2249,23 @@ constexpr C c(0); struct D : A { - using A::A; // expected-note {{here}} + using A::A; // cxx11-note {{here}} struct { // expected-warning {{extension}} union { // expected-warning {{extension}} int n; }; }; }; - constexpr D d(0); // expected-error {{constant expression}} expected-note {{derived class}} + constexpr D d(0); // cxx11-error {{constant expression}} cxx11-note {{derived class}} struct E : virtual A { using A::A; }; // expected-note {{here}} + // cxx20_2b-note@-1 {{struct with virtual base class is not a literal type}} // We wrap a function around this to avoid implicit zero-initialization // happening first; the zero-initialization step would produce the same // error and defeat the point of this test. void f() { - constexpr E e(0); // expected-error {{constant expression}} expected-note {{derived class}} + constexpr E e(0); // cxx11-error {{constant expression}} cxx11-note {{derived class}} + // cxx20_2b-error@-1 {{constexpr variable cannot have non-literal type}} } // FIXME: This produces a note with no source location. //constexpr E e(0); diff --git a/clang/test/SemaCXX/constant-expression-cxx1y.cpp b/clang/test/SemaCXX/constant-expression-cxx14.cpp rename from clang/test/SemaCXX/constant-expression-cxx1y.cpp rename to clang/test/SemaCXX/constant-expression-cxx14.cpp --- a/clang/test/SemaCXX/constant-expression-cxx1y.cpp +++ b/clang/test/SemaCXX/constant-expression-cxx14.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -std=c++1y -verify %s -fcxx-exceptions -triple=x86_64-linux-gnu +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx20_2b %s -fcxx-exceptions -triple=x86_64-linux-gnu +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx20_2b %s -fcxx-exceptions -triple=x86_64-linux-gnu +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=expected,cxx14 %s -fcxx-exceptions -triple=x86_64-linux-gnu struct S { // dummy ctor to make this a literal type @@ -225,6 +227,7 @@ // expected-note@-2 {{assignment to member 'c' of union with active member 'n'}} } constexpr bool check(D &d) { return d.c.a.y == 3; } + // cxx20_2b-note@-1 {{read of member 'y' of union with active member 'x' is not allowed in a constant expression}} constexpr bool g() { D d; f(d); return d.c.a.y == 3; } static_assert(g(), ""); @@ -236,7 +239,8 @@ constexpr bool i() { D d(0); f(d); return check(d); } // expected-note {{in call}} static_assert(i(), ""); // expected-error {{constant expression}} expected-note {{in call}} - constexpr bool j() { D d; d.c.a.x = 3; return check(d); } // expected-note {{assignment to member 'x' of union with active member 'y'}} + constexpr bool j() { D d; d.c.a.x = 3; return check(d); } // cxx14-note {{assignment to member 'x' of union with active member 'y'}} + // cxx20_2b-note@-1 {{in call to 'check(d)'}} static_assert(j(), ""); // expected-error {{constant expression}} expected-note {{in call}} } @@ -285,8 +289,10 @@ static_assert(--ref(0x8000) == 0x7fff, ""); // inc on bool sets to true - static_assert(++ref(false), ""); // expected-warning {{deprecated}} - static_assert(++ref(true), ""); // expected-warning {{deprecated}} + static_assert(++ref(false), ""); // cxx14-warning {{deprecated}} + // cxx20_2b-error@-1 {{ISO C++17 does not allow incrementing expression of type bool}} + static_assert(++ref(true), ""); // cxx14-warning {{deprecated}} + // cxx20_2b-error@-1 {{ISO C++17 does not allow incrementing expression of type bool}} int arr[10]; static_assert(++ref(&arr[0]) == &arr[1], ""); @@ -323,6 +329,7 @@ } constexpr int wrong_member = f({0}); // expected-error {{constant}} expected-note {{in call to 'f({.a = 0})'}} constexpr int vol = --ref(0); // expected-error {{constant}} expected-note {{decrement of volatile-qualified}} + // cxx20_2b-warning@-1 {{decrement of object of volatile-qualified type 'volatile int' is deprecated}} constexpr int incr(int k) { int x = k; @@ -849,7 +856,7 @@ // Virtual f(), not OK. constexpr X> xxs2; constexpr X *q = const_cast>*>(&xxs2); - static_assert(q->f() == sizeof(X), ""); // expected-error {{constant expression}} expected-note {{virtual function}} + static_assert(q->f() == sizeof(X), ""); // cxx14-error {{constant expression}} cxx14-note {{virtual function}} } namespace Lifetime { @@ -1091,12 +1098,12 @@ struct A { struct { union { - int x = x = 3; // expected-note {{outside its lifetime}} + int x = x = 3; // cxx14-note {{outside its lifetime}} }; }; constexpr A() {} }; -static_assert(A().x == 3, ""); // expected-error{{not an integral constant expression}} expected-note{{in call to 'A()'}} +static_assert(A().x == 3, ""); // cxx14-error{{not an integral constant expression}} cxx14-note{{in call to 'A()'}} // Reference another indirect field, with different 'this'. struct B { diff --git a/clang/test/SemaCXX/conversion-function.cpp b/clang/test/SemaCXX/conversion-function.cpp --- a/clang/test/SemaCXX/conversion-function.cpp +++ b/clang/test/SemaCXX/conversion-function.cpp @@ -1,8 +1,10 @@ -// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -Wbind-to-temporary-copy -verify %s -// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -Wbind-to-temporary-copy -verify -std=c++98 %s -// RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -Wbind-to-temporary-copy -verify -std=c++11 %s +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected -triple %itanium_abi_triple -Wbind-to-temporary-copy %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected -triple %itanium_abi_triple -Wbind-to-temporary-copy %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=expected,cxx98_14 -triple %itanium_abi_triple -Wbind-to-temporary-copy %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx98_14 -triple %itanium_abi_triple -Wbind-to-temporary-copy %s +// RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify=expected,cxx98_14 -triple %itanium_abi_triple -Wbind-to-temporary-copy %s -class X { +class X { public: operator bool(); operator int() const; @@ -31,11 +33,11 @@ // expected-error{{conversion function cannot have any parameters}} operator bool(int a = 4, int b = 6) const; // expected-error{{conversion function cannot have any parameters}} - - + + operator float(...) const; // expected-error{{conversion function cannot be variadic}} - - + + operator func_type(); // expected-error{{conversion function cannot convert to a function type}} operator array_type(); // expected-error{{conversion function cannot convert to an array type}} }; @@ -44,10 +46,10 @@ typedef int INT; typedef INT* INT_PTR; -class Z { +class Z { operator int(); // expected-note {{previous declaration is here}} operator int**(); // expected-note {{previous declaration is here}} - + operator INT(); // expected-error{{conversion function cannot be redeclared}} operator INT_PTR*(); // expected-error{{conversion function cannot be redeclared}} }; @@ -103,12 +105,12 @@ } // Test. Conversion in base class is visible in derived class. -class XB { +class XB { public: operator int(); // expected-note {{candidate function}} }; -class Yb : public XB { +class Yb : public XB { public: operator char(); // expected-note {{candidate function}} }; @@ -123,12 +125,12 @@ class AutoPtrRef { }; class AutoPtr { - AutoPtr(AutoPtr &); // expected-note{{declared private here}} - + AutoPtr(AutoPtr &); // cxx98_14-note{{declared private here}} + public: AutoPtr(); AutoPtr(AutoPtrRef); - + operator AutoPtrRef(); }; @@ -136,11 +138,11 @@ AutoPtr test_auto_ptr(bool Cond) { AutoPtr p1( make_auto_ptr() ); - + AutoPtr p; if (Cond) - return p; // expected-error{{calling a private constructor}} - + return p; // cxx98_14-error{{calling a private constructor}} + return AutoPtr(); } @@ -149,16 +151,16 @@ ~A1(); private: - A1(const A1&); // expected-note 2 {{declared private here}} + A1(const A1&); // cxx98_14-note 2 {{declared private here}} }; A1 f() { // FIXME: redundant diagnostics! - return "Hello"; // expected-error {{calling a private constructor}} + return "Hello"; // cxx98_14-error {{calling a private constructor}} #if __cplusplus <= 199711L // expected-warning@-2 {{an accessible copy constructor}} #else - // expected-warning@-4 {{copying parameter of type 'A1' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}} + // cxx98_14-warning@-4 {{copying parameter of type 'A1' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}} #endif } @@ -185,7 +187,7 @@ const A &caf2 = E(); } - // Check + // Check template struct E2 { operator T @@ -212,7 +214,7 @@ } namespace smart_ptr { - class Y { + class Y { class YRef { }; Y(Y&); @@ -246,7 +248,7 @@ }; struct Other { - Other(const Other &); + Other(const Other &); Other(); }; @@ -289,7 +291,7 @@ struct Y { Y(X); }; - + Y f2(foo()); } @@ -339,7 +341,7 @@ struct Derived2 : Base { }; - struct SuperDerived : Derived1, Derived2 { + struct SuperDerived : Derived1, Derived2 { using Derived1::operator int; }; @@ -359,7 +361,7 @@ operator int(); }; - struct Derived23 : Base2, Base3 { + struct Derived23 : Base2, Base3 { using Base2::operator int; }; @@ -404,7 +406,7 @@ { template operator Container() - { + { Container ar; T* i; ar[0]=*i; diff --git a/clang/test/SemaCXX/coroutine-rvo.cpp b/clang/test/SemaCXX/coroutine-rvo.cpp --- a/clang/test/SemaCXX/coroutine-rvo.cpp +++ b/clang/test/SemaCXX/coroutine-rvo.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only +// RUN: %clang_cc1 -verify -std=c++17 -fcoroutines-ts -fsyntax-only %s namespace std::experimental { template struct coroutine_handle { @@ -39,10 +39,14 @@ }; struct MoveOnly { - MoveOnly() {}; + MoveOnly() = default; MoveOnly(const MoveOnly&) = delete; - MoveOnly(MoveOnly&&) noexcept {}; - ~MoveOnly() {}; + MoveOnly(MoveOnly &&) = default; +}; + +struct NoCopyNoMove { + NoCopyNoMove() = default; + NoCopyNoMove(const NoCopyNoMove &) = delete; // expected-note 4{{'NoCopyNoMove' has been explicitly marked deleted here}} }; template @@ -52,18 +56,95 @@ auto final_suspend() noexcept { return suspend_never{}; } auto get_return_object() { return task{}; } static void unhandled_exception() {} - void return_value(T&& value) {} + void return_value(T &&value) {} // expected-note 4{{passing argument}} }; }; -task f() { - MoveOnly value; +task local2val() { + NoCopyNoMove value; + co_return value; // expected-error {{call to deleted constructor of 'NoCopyNoMove'}} + // expected-error@-1 {{value reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}} +} + +task local2ref() { + NoCopyNoMove value; + co_return value; // expected-error {{call to deleted constructor of 'NoCopyNoMove'}} +} + +// We need the move constructor for construction of the coroutine. +task param2val(MoveOnly value) { + co_return value; +} + +task lvalue2val(NoCopyNoMove &value) { + co_return value; // expected-error {{rvalue reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}} +} + +task rvalue2val(NoCopyNoMove &&value) { + co_return value; // expected-error {{rvalue reference to type 'NoCopyNoMove' cannot bind to lvalue of type 'NoCopyNoMove'}} + // expected-error@-1 {{call to deleted constructor of 'NoCopyNoMove'}} +} + +task lvalue2ref(NoCopyNoMove &value) { co_return value; } -int main() { - f(); - return 0; +task rvalue2ref(NoCopyNoMove &&value) { + co_return value; // expected-error {{call to deleted constructor of 'NoCopyNoMove'}} +} + +struct To { + operator MoveOnly() &&; +}; +task conversion_operator() { + To t; + co_return t; +} + +struct Construct { + Construct(MoveOnly); +}; +task converting_constructor() { + MoveOnly w; + co_return w; +} + +struct Derived : MoveOnly {}; +task derived2base() { + Derived result; + co_return result; +} + +struct RetThis { + task foo() && { + co_return *this; // expected-error {{rvalue reference to type 'RetThis' cannot bind to lvalue of type 'RetThis'}} + } +}; + +template +struct is_same { static constexpr bool value = false; }; + +template +struct is_same { static constexpr bool value = true; }; + +template +struct template_return_task { + struct promise_type { + auto initial_suspend() { return suspend_never{}; } + auto final_suspend() noexcept { return suspend_never{}; } + auto get_return_object() { return template_return_task{}; } + static void unhandled_exception(); + template + void return_value(U &&value) { + static_assert(is_same::value); + } + }; +}; + +template_return_task param2template(MoveOnly value) { + co_return value; // We should deduce U = MoveOnly. } -// expected-no-diagnostics +template_return_task lvalue2template(NoCopyNoMove &value) { + co_return value; // We should deduce U = NoCopyNoMove&. +} diff --git a/clang/test/SemaCXX/coroutines.cpp b/clang/test/SemaCXX/coroutines.cpp --- a/clang/test/SemaCXX/coroutines.cpp +++ b/clang/test/SemaCXX/coroutines.cpp @@ -1,7 +1,9 @@ // This file contains references to sections of the Coroutines TS, which can be // found at http://wg21.link/coroutines. -// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions -fexceptions -Wunused-result +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx20_2b %s -fcxx-exceptions -fexceptions -Wunused-result +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx20_2b %s -fcxx-exceptions -fexceptions -Wunused-result +// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -fsyntax-only -verify=expected %s -fcxx-exceptions -fexceptions -Wunused-result void no_coroutine_traits_bad_arg_await() { co_await a; // expected-error {{include }} @@ -1012,6 +1014,7 @@ // expected-error@+2 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &')}} // expected-error@+1 {{return type of 'await_suspend' is required to be 'void' or 'bool' (have 'bool &&')}} SuspendTy await_suspend(std::experimental::coroutine_handle<>); + // cxx20_2b-warning@-1 {{volatile-qualified return type 'const volatile bool' is deprecated}} void await_resume(); }; void test_bad_suspend() { @@ -1033,7 +1036,7 @@ await_suspend_type_test a; await_suspend_type_test b; await_suspend_type_test c; - await_suspend_type_test d; + await_suspend_type_test d; // cxx20_2b-note {{in instantiation of template class}} co_await a; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}} co_await b; // expected-note {{call to 'await_suspend' implicitly required by coroutine function here}} co_await c; // OK @@ -1121,6 +1124,7 @@ } CoroMemberTag test_qual(int *, const float &&, volatile void *volatile) const { + // cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void *volatile' is deprecated}} auto TC = co_yield 0; static_assert(TC.MatchesArgs, ""); } @@ -1219,6 +1223,7 @@ } CoroMemberTag test_qual(int *, const float &&, volatile void *volatile) const { + // cxx20_2b-warning@-1 {{volatile-qualified parameter type 'volatile void *volatile' is deprecated}} auto TC = co_yield 0; static_assert(TC.template MatchesArgs, ""); } diff --git a/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp rename from clang/test/SemaCXX/cxx1y-deduced-return-type.cpp rename to clang/test/SemaCXX/deduced-return-type-cxx14.cpp --- a/clang/test/SemaCXX/cxx1y-deduced-return-type.cpp +++ b/clang/test/SemaCXX/deduced-return-type-cxx14.cpp @@ -1,5 +1,11 @@ -// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s -// RUN: %clang_cc1 -std=c++1y -verify -fsyntax-only %s -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx20_2b %s +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected,cxx20_2b %s -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING + +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx20_2b %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx20_2b %s -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING + +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=expected,cxx14 %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=expected,cxx14 %s -fdelayed-template-parsing -DDELAYED_TEMPLATE_PARSING auto f(); // expected-note {{previous}} int f(); // expected-error {{differ only in their return type}} @@ -287,7 +293,8 @@ Y().f(); constexpr int q = Y().f(); // expected-error {{must be initialized by a constant expression}} expected-note {{in call to '&Y()->f()'}} } - struct NonLiteral { ~NonLiteral(); } nl; // expected-note {{user-provided destructor}} + struct NonLiteral { ~NonLiteral(); } nl; // cxx14-note {{user-provided destructor}} + // cxx20_2b-note@-1 {{'NonLiteral' is not literal because its destructor is not constexpr}} constexpr auto f2(int n) { return nl; } // expected-error {{return type 'Constexpr::NonLiteral' is not a literal type}} } @@ -377,7 +384,7 @@ return 5; } template operator T() { return T{}; } - operator auto() { return &static_foo; } + operator auto() { return &static_foo; } }; struct N : M { using M::foo; @@ -385,7 +392,7 @@ using M::static_foo; using M::operator auto; }; - + template int test() { int i = T{}.foo(3); T m = T{}.foo(M{}); @@ -400,7 +407,7 @@ } int Minst = test(); int Ninst = test(); - + } } @@ -451,11 +458,11 @@ auto f(); // expected-note {{here}} int g() { return f(); } // expected-error {{cannot be used before it is defined}} #else - auto f(); - int g() { return f(); } + auto f(); + int g() { return f(); } #endif }; - #ifndef DELAYED_TEMPLATE_PARSING + #ifndef DELAYED_TEMPLATE_PARSING template int U::g(); // expected-note {{in instantiation of}} #else template int U::g(); @@ -624,7 +631,7 @@ namespace PR46637 { using A = auto () -> auto; // expected-error {{'auto' not allowed in type alias}} using B = auto (*)() -> auto; // expected-error {{'auto' not allowed in type alias}} - template auto> struct X {}; // expected-error {{'auto' not allowed in template parameter until C++17}} + template auto> struct X {}; // cxx14-error {{'auto' not allowed in template parameter until C++17}} template struct Y { T x; }; Y auto> y; // expected-error {{'auto' not allowed in template argument}} } diff --git a/clang/test/SemaCXX/return-stack-addr.cpp b/clang/test/SemaCXX/return-stack-addr.cpp --- a/clang/test/SemaCXX/return-stack-addr.cpp +++ b/clang/test/SemaCXX/return-stack-addr.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=expected %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11 %s int* ret_local() { int x = 1; @@ -179,12 +181,12 @@ }; (void) [] { int a; - // expected-warning@+1 {{C++14}} + // cxx11-warning@+1 {{C++14}} return [&b = a] {}; // expected-warning {{address of stack memory associated with local variable 'a' returned}} expected-note {{captured by reference via initialization of lambda capture 'b'}} }; (void) [] { int a; - // expected-warning@+1 {{C++14}} + // cxx11-warning@+1 {{C++14}} return [b = &a] {}; // expected-warning {{address of stack memory associated with local variable 'a' returned}} expected-note {{captured via initialization of lambda capture 'b'}} }; } @@ -197,7 +199,7 @@ } HoldsPointer ret_via_member_2() { int n; - return HoldsPointer(HoldsPointer{&n}); // expected-warning {{address of stack memory associated with local variable 'n' returned}} + return HoldsPointer(HoldsPointer{&n}); // cxx11-warning {{address of stack memory associated with local variable 'n' returned}} } // FIXME: We could diagnose this too. HoldsPointer ret_via_member_3() { diff --git a/clang/test/SemaCXX/warn-return-std-move.cpp b/clang/test/SemaCXX/warn-return-std-move.cpp --- a/clang/test/SemaCXX/warn-return-std-move.cpp +++ b/clang/test/SemaCXX/warn-return-std-move.cpp @@ -1,10 +1,12 @@ -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++20 -verify=cxx20 %s -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -verify=expected %s -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -verify=expected %s -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -verify=expected %s -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++17 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++14 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK -// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK +// RUN: %clang_cc1 -std=c++2b -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20_2b -fcxx-exceptions -Wreturn-std-move %s +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=cxx11_17 -fcxx-exceptions -Wreturn-std-move %s + +// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK +// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK +// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -Wreturn-std-move -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s -check-prefix=CHECK // definitions for std::move namespace std { @@ -76,8 +78,8 @@ Base test2() { Derived d2; return d2; // e1 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)" } ConstructFromDerived test3() { @@ -87,22 +89,22 @@ ConstructFromBase test4() { Derived d4; return d4; // e3 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)" } ConvertFromDerived test5() { Derived d5; return d5; // e4 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)" } ConvertFromBase test6() { Derived d6; return d6; // e5 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)" } @@ -150,8 +152,8 @@ Derived testParam1(Derived d) { return d; } Base testParam2(Derived d) { return d; // e6 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConstructFromDerived testParam3(Derived d) { @@ -159,58 +161,58 @@ } ConstructFromBase testParam4(Derived d) { return d; // e8 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConvertFromDerived testParam5(Derived d) { return d; // e9 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConvertFromBase testParam6(Derived d) { return d; // e10 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } // If the target is an rvalue reference parameter, do apply the diagnostic. Derived testRParam1(Derived&& d) { return d; // e11 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } Base testRParam2(Derived&& d) { return d; // e12 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConstructFromDerived testRParam3(Derived&& d) { return d; // e13 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConstructFromBase testRParam4(Derived&& d) { return d; // e14 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConvertFromDerived testRParam5(Derived&& d) { return d; // e15 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } ConvertFromBase testRParam6(Derived&& d) { return d; // e16 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:13}:"std::move(d)" } @@ -226,8 +228,8 @@ Base testParens1() { Derived d; return (d); // e17 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:15}:"std::move(d)" } ConstructFromDerived testParens2() { @@ -239,43 +241,43 @@ void throw_derived(); Derived testEParam1() { try { throw_derived(); } catch (Derived d) { return d; } // e19 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } Base testEParam2() { try { throw_derived(); } catch (Derived d) { return d; } // e20 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } ConstructFromDerived testEParam3() { try { throw_derived(); } catch (Derived d) { return d; } // e21 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } ConstructFromBase testEParam4() { try { throw_derived(); } catch (Derived d) { return d; } // e22 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } ConvertFromDerived testEParam5() { try { throw_derived(); } catch (Derived d) { return d; } // e23 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } ConvertFromBase testEParam6() { try { throw_derived(); } catch (Derived d) { return d; } // e24 - // expected-warning@-1{{will be copied despite being returned by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being returned by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:57-[[@LINE-3]]:58}:"std::move(d)" __builtin_unreachable(); } @@ -316,8 +318,8 @@ void test_throw1(Derived&& d) { throw d; // e25 - // expected-warning@-1{{will be copied despite being thrown by name}} - // expected-note@-2{{to avoid copying}} + // cxx11_17-warning@-1{{will be copied despite being thrown by name}} + // cxx11_17-note@-2{{to avoid copying}} // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:12}:"std::move(d)" } @@ -336,7 +338,7 @@ namespace test_delete { struct Base { Base(); - Base(Base &&) = delete; // cxx20-note {{'Base' has been explicitly marked deleted here}} + Base(Base &&) = delete; // cxx20_2b-note {{'Base' has been explicitly marked deleted here}} Base(Base const &); }; @@ -344,6 +346,6 @@ Base test_ok() { Derived d; - return d; // cxx20-error {{call to deleted constructor of 'test_delete::Base'}} + return d; // cxx20_2b-error {{call to deleted constructor of 'test_delete::Base'}} } } // namespace test_delete