From: Sean Hunt Date: Fri, 13 May 2011 01:01:05 +0000 (+0000) Subject: Implement a few basic tests for defaulted and deleted functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7880bc34fd5818d8f1eb827fdce136c1de643ab5;p=clang Implement a few basic tests for defaulted and deleted functions. More comprehensive testing once copy {constructors,assignment operators} can be defaulted. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131275 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/PCH/cxx0x-default-delete.cpp b/test/PCH/cxx0x-default-delete.cpp new file mode 100644 index 0000000000..20b0c7f39c --- /dev/null +++ b/test/PCH/cxx0x-default-delete.cpp @@ -0,0 +1,23 @@ +// Without PCH +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify -include %s %s +// With PCH +// RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %s +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify -include-pch %t %s + +#ifndef PASS1 +#define PASS1 + +struct foo { + foo() = default; + void bar() = delete; // expected-note{{deleted here}} +}; + +#else + +foo::foo() { } // expected-error{{definition of explicitly defaulted}} +foo f; +void fn() { + f.bar(); // expected-error{{deleted function}} +} + +#endif diff --git a/test/Parser/cxx-default-delete.cpp b/test/Parser/cxx-default-delete.cpp new file mode 100644 index 0000000000..a3d5b2c1d9 --- /dev/null +++ b/test/Parser/cxx-default-delete.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +int i = delete; // expected-error{{only functions}} +int j = default; // expected-error{{special member functions}} + +int f() = delete, g; // expected-error{{standalone}} +int o, p() = delete; // expected-error{{standalone}} + +struct foo { + foo() = default; + ~foo() = delete; + void bar() = delete; +}; + +void baz() = delete; diff --git a/test/Parser/cxx-ext-delete-default.cpp b/test/Parser/cxx-ext-delete-default.cpp new file mode 100644 index 0000000000..0627238514 --- /dev/null +++ b/test/Parser/cxx-ext-delete-default.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s + +struct A { + A(const A&) = delete; // expected-warning {{accepted as a C++0x extension}} + A& operator=(const A&) = delete; // expected-warning {{accepted as a C++0x extension}} + A() = default; // expected-warning {{accepted as a C++0x extension}} + ~A(); +}; + +void f() = delete; // expected-warning {{accepted as a C++0x extension}} +A::~A() = default; //expected-warning {{accepted as a C++0x extension}} diff --git a/test/SemaCXX/deleted-function-extension.cpp b/test/SemaCXX/deleted-function-extension.cpp deleted file mode 100644 index fdf5ac8bd5..0000000000 --- a/test/SemaCXX/deleted-function-extension.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s - -struct A { - A(const A&) = delete; // expected-warning {{deleted function definition accepted as a C++0x extension}} - A& operator=(const A&) = delete; // expected-warning {{deleted function definition accepted as a C++0x extension}} -}; - -void f() = delete; // expected-warning {{deleted function definition accepted as a C++0x extension}}