llvm-project/clang/test/SemaCXX/P1155.cpp

71 lines
2.0 KiB
C++

// 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_17 %s
// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions -verify=cxx11_17 %s
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions -verify=cxx11_17 %s
// cxx20_2b-no-diagnostics
// Throwing
namespace test_throwing {
class Widget {
public:
Widget(Widget &&);
Widget(const Widget &) = delete;
};
void seven(Widget w) {
throw w; // Clang already do this implicit move before -std=c++20
}
} // namespace test_throwing
// Non-constructor conversion
namespace test_non_constructor_conversion {
class Widget {};
struct To {
operator Widget() const & = delete; // cxx11_17-note {{'operator Widget' has been explicitly marked deleted here}}
operator Widget() &&;
};
Widget nine() {
To t;
return t; // cxx11_17-error {{conversion function from 'test_non_constructor_conversion::To' to 'test_non_constructor_conversion::Widget' invokes a deleted function}}
}
} // namespace test_non_constructor_conversion
// By-value sinks
namespace test_by_value_sinks {
class Widget {
public:
Widget();
Widget(Widget &&);
Widget(const Widget &) = delete; // cxx11_17-note {{'Widget' has been explicitly marked deleted here}}
};
struct Fowl {
Fowl(Widget); // cxx11_17-note {{passing argument to parameter here}}
};
Fowl eleven() {
Widget w;
return w; // cxx11_17-error {{call to deleted constructor of 'test_by_value_sinks::Widget'}}
}
} // namespace test_by_value_sinks
// Slicing
namespace test_slicing {
class Base {
public:
Base();
Base(Base &&);
Base(Base const &) = delete; // cxx11_17-note {{'Base' has been explicitly marked deleted here}}
};
class Derived : public Base {};
Base thirteen() {
Derived result;
return result; // cxx11_17-error {{call to deleted constructor of 'test_slicing::Base'}}
}
} // namespace test_slicing