summaryrefslogtreecommitdiff
path: root/test/SemaCXX
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX')
-rw-r--r--test/SemaCXX/constant-expression-cxx11.cpp16
-rw-r--r--test/SemaCXX/eval-crashes.cpp56
-rw-r--r--test/SemaCXX/type-traits.cpp25
-rw-r--r--test/SemaCXX/unavailable_aligned_allocation.cpp109
-rw-r--r--test/SemaCXX/warn-throw-out-noexcept-func.cpp37
5 files changed, 238 insertions, 5 deletions
diff --git a/test/SemaCXX/constant-expression-cxx11.cpp b/test/SemaCXX/constant-expression-cxx11.cpp
index 4abbc8e928479..3fda2d0a7fd0e 100644
--- a/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/test/SemaCXX/constant-expression-cxx11.cpp
@@ -608,7 +608,7 @@ namespace DependentValues {
struct I { int n; typedef I V[10]; };
I::V x, y;
-int g();
+int g(); // expected-note {{declared here}}
template<bool B, typename T> struct S : T {
int k;
void f() {
@@ -616,13 +616,23 @@ template<bool B, typename T> struct S : T {
I &i = cells[k];
switch (i.n) {}
- // FIXME: We should be able to diagnose this.
- constexpr int n = g();
+ constexpr int n = g(); // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr function 'g'}}
constexpr int m = this->g(); // ok, could be constexpr
}
};
+extern const int n;
+template<typename T> void f() {
+ // This is ill-formed, because a hypothetical instantiation at the point of
+ // template definition would be ill-formed due to a construct that does not
+ // depend on a template parameter.
+ constexpr int k = n; // expected-error {{must be initialized by a constant expression}}
+}
+// It doesn't matter that the instantiation could later become valid:
+constexpr int n = 4;
+template void f<int>();
+
}
namespace Class {
diff --git a/test/SemaCXX/eval-crashes.cpp b/test/SemaCXX/eval-crashes.cpp
new file mode 100644
index 0000000000000..23946845d8ed1
--- /dev/null
+++ b/test/SemaCXX/eval-crashes.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -std=c++1z -verify %s
+
+namespace pr32864_0 {
+ struct transfer_t {
+ void *fctx;
+ };
+ template <typename Ctx> class record {
+ void run() {
+ transfer_t t;
+ Ctx from{t.fctx};
+ }
+ };
+}
+
+namespace pr33140_0a {
+ struct S {
+ constexpr S(const int &a = 0) {}
+ };
+ void foo(void) { S s[2] = {}; }
+}
+
+namespace pr33140_0b {
+ bool bar(float const &f = 0);
+ bool foo() { return bar() && bar(); }
+}
+
+namespace pr33140_2 {
+ // FIXME: The declaration of 'b' below should lifetime-extend two int
+ // temporaries, invalidating this warning to some extent.
+ struct A { int &&r = 0; }; // expected-warning {{binding reference member 'r' to a temporary}} expected-note {{here}}
+ struct B { A x, y; };
+ B b = {};
+}
+
+namespace pr33140_3 {
+ typedef struct Y { unsigned int c; } Y_t;
+ struct X {
+ Y_t a;
+ };
+ struct X foo[2] = {[0 ... 1] = {.a = (Y_t){.c = 0}}};
+}
+
+namespace pr33140_6 {
+ struct Y { unsigned int c; };
+ struct X { struct Y *p; };
+ int f() {
+ // FIXME: This causes clang to crash.
+ //return (struct X[2]){ [0 ... 1] = { .p = &(struct Y&)(struct Y&&)(struct Y){0} } }[0].p->c;
+ return 0;
+ }
+}
+
+namespace pr33140_10 {
+ int a(const int &n = 0);
+ bool b() { return a() == a(); }
+}
diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp
index 8a994f01ba1a9..5879a77dd5a84 100644
--- a/test/SemaCXX/type-traits.cpp
+++ b/test/SemaCXX/type-traits.cpp
@@ -1447,7 +1447,9 @@ void has_trivial_default_constructor() {
{ int arr[T(__has_trivial_constructor(const Int))]; }
{ int arr[T(__has_trivial_constructor(AllDefaulted))]; }
{ int arr[T(__has_trivial_constructor(AllDeleted))]; }
+ { int arr[T(__has_trivial_constructor(ACompleteType[]))]; }
+ { int arr[F(__has_trivial_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_constructor(HasCons))]; }
{ int arr[F(__has_trivial_constructor(HasRef))]; }
{ int arr[F(__has_trivial_constructor(HasCopy))]; }
@@ -1478,7 +1480,9 @@ void has_trivial_move_constructor() {
{ int arr[T(__has_trivial_move_constructor(HasCons))]; }
{ int arr[T(__has_trivial_move_constructor(HasStaticMemberMoveCtor))]; }
{ int arr[T(__has_trivial_move_constructor(AllDeleted))]; }
-
+ { int arr[T(__has_trivial_move_constructor(ACompleteType[]))]; }
+
+ { int arr[F(__has_trivial_move_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_move_constructor(HasVirt))]; }
{ int arr[F(__has_trivial_move_constructor(DerivesVirt))]; }
{ int arr[F(__has_trivial_move_constructor(HasMoveCtor))]; }
@@ -1508,7 +1512,9 @@ void has_trivial_copy_constructor() {
{ int arr[T(__has_trivial_copy(AllDeleted))]; }
{ int arr[T(__has_trivial_copy(DerivesAr))]; }
{ int arr[T(__has_trivial_copy(DerivesHasRef))]; }
+ { int arr[T(__has_trivial_copy(ACompleteType[]))]; }
+ { int arr[F(__has_trivial_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_copy(HasCopy))]; }
{ int arr[F(__has_trivial_copy(HasTemplateCons))]; }
{ int arr[F(__has_trivial_copy(VirtAr))]; }
@@ -1536,7 +1542,9 @@ void has_trivial_copy_assignment() {
{ int arr[T(__has_trivial_assign(AllDeleted))]; }
{ int arr[T(__has_trivial_assign(DerivesAr))]; }
{ int arr[T(__has_trivial_assign(DerivesHasRef))]; }
+ { int arr[T(__has_trivial_assign(ACompleteType[]))]; }
+ { int arr[F(__has_trivial_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_assign(IntRef))]; }
{ int arr[F(__has_trivial_assign(HasCopyAssign))]; }
{ int arr[F(__has_trivial_assign(const Int))]; }
@@ -1572,8 +1580,10 @@ void has_trivial_destructor() {
{ int arr[T(__has_trivial_destructor(AllDefaulted))]; }
{ int arr[T(__has_trivial_destructor(AllDeleted))]; }
{ int arr[T(__has_trivial_destructor(DerivesHasRef))]; }
+ { int arr[T(__has_trivial_destructor(ACompleteType[]))]; }
{ int arr[F(__has_trivial_destructor(HasDest))]; }
+ { int arr[F(__has_trivial_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_destructor(void))]; }
{ int arr[F(__has_trivial_destructor(cvoid))]; }
{ int arr[F(__has_trivial_destructor(AllPrivate))]; }
@@ -1625,7 +1635,9 @@ void has_nothrow_assign() {
{ int arr[T(__has_nothrow_assign(AllPrivate))]; }
{ int arr[T(__has_nothrow_assign(UsingAssign))]; }
{ int arr[T(__has_nothrow_assign(DerivesAr))]; }
+ { int arr[T(__has_nothrow_assign(ACompleteType[]))]; }
+ { int arr[F(__has_nothrow_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_nothrow_assign(IntRef))]; }
{ int arr[F(__has_nothrow_assign(HasCopyAssign))]; }
{ int arr[F(__has_nothrow_assign(HasMultipleCopyAssign))]; }
@@ -1650,8 +1662,9 @@ void has_nothrow_move_assign() {
{ int arr[T(__has_nothrow_move_assign(HasMemberNoThrowMoveAssign))]; }
{ int arr[T(__has_nothrow_move_assign(HasMemberNoExceptNoThrowMoveAssign))]; }
{ int arr[T(__has_nothrow_move_assign(AllDeleted))]; }
+ { int arr[T(__has_nothrow_move_assign(ACompleteType[]))]; }
-
+ { int arr[F(__has_nothrow_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_nothrow_move_assign(HasThrowMoveAssign))]; }
{ int arr[F(__has_nothrow_move_assign(HasNoExceptFalseMoveAssign))]; }
{ int arr[F(__has_nothrow_move_assign(HasMemberThrowMoveAssign))]; }
@@ -1683,7 +1696,9 @@ void has_trivial_move_assign() {
{ int arr[T(__has_trivial_move_assign(Int))]; }
{ int arr[T(__has_trivial_move_assign(HasStaticMemberMoveAssign))]; }
{ int arr[T(__has_trivial_move_assign(AllDeleted))]; }
+ { int arr[T(__has_trivial_move_assign(ACompleteType[]))]; }
+ { int arr[F(__has_trivial_move_assign(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_trivial_move_assign(HasVirt))]; }
{ int arr[F(__has_trivial_move_assign(DerivesVirt))]; }
{ int arr[F(__has_trivial_move_assign(HasMoveAssign))]; }
@@ -1717,7 +1732,9 @@ void has_nothrow_copy() {
{ int arr[T(__has_nothrow_copy(HasTemplateCons))]; }
{ int arr[T(__has_nothrow_copy(AllPrivate))]; }
{ int arr[T(__has_nothrow_copy(DerivesAr))]; }
+ { int arr[T(__has_nothrow_copy(ACompleteType[]))]; }
+ { int arr[F(__has_nothrow_copy(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_nothrow_copy(HasCopy))]; }
{ int arr[F(__has_nothrow_copy(HasMultipleCopy))]; }
{ int arr[F(__has_nothrow_copy(VirtAr))]; }
@@ -1743,7 +1760,9 @@ void has_nothrow_constructor() {
{ int arr[T(__has_nothrow_constructor(HasVirtDest))]; }
// { int arr[T(__has_nothrow_constructor(VirtAr))]; } // not implemented
{ int arr[T(__has_nothrow_constructor(AllPrivate))]; }
+ { int arr[T(__has_nothrow_constructor(ACompleteType[]))]; }
+ { int arr[F(__has_nothrow_constructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[F(__has_nothrow_constructor(HasCons))]; }
{ int arr[F(__has_nothrow_constructor(HasRef))]; }
{ int arr[F(__has_nothrow_constructor(HasCopy))]; }
@@ -1779,7 +1798,9 @@ void has_virtual_destructor() {
{ int arr[F(__has_virtual_destructor(HasMoveAssign))]; }
{ int arr[F(__has_virtual_destructor(IntRef))]; }
{ int arr[F(__has_virtual_destructor(VirtAr))]; }
+ { int arr[F(__has_virtual_destructor(ACompleteType[]))]; }
+ { int arr[F(__has_virtual_destructor(AnIncompleteType[]))]; } // expected-error {{incomplete type}}
{ int arr[T(__has_virtual_destructor(HasVirtDest))]; }
{ int arr[T(__has_virtual_destructor(DerivedVirtDest))]; }
{ int arr[F(__has_virtual_destructor(VirtDestAr))]; }
diff --git a/test/SemaCXX/unavailable_aligned_allocation.cpp b/test/SemaCXX/unavailable_aligned_allocation.cpp
new file mode 100644
index 0000000000000..2ae5d2e2c7041
--- /dev/null
+++ b/test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s
+
+namespace std {
+ typedef decltype(sizeof(0)) size_t;
+ enum class align_val_t : std::size_t {};
+ struct nothrow_t {};
+ nothrow_t nothrow;
+}
+
+void *operator new(std::size_t __sz, const std::nothrow_t&) noexcept;
+void *operator new[](std::size_t __sz, const std::nothrow_t&) noexcept;
+
+void *operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept;
+void *operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) noexcept;
+void operator delete(void *, std::align_val_t, const std::nothrow_t&);
+void operator delete[](void *, std::align_val_t, const std::nothrow_t&);
+void operator delete(void*, std::size_t, std::align_val_t) noexcept;
+void operator delete[](void*, std::size_t, std::align_val_t) noexcept;
+
+void *operator new(std::size_t, std::align_val_t, long long);
+
+struct alignas(256) OveralignedS {
+ int x[16];
+};
+
+struct S {
+ int x[16];
+};
+
+void test() {
+ auto *p = new S;
+ delete p;
+ p = new (std::nothrow) S;
+
+ auto *pa = new S[4];
+ delete[] pa;
+ pa = new (std::nothrow) S[4];
+}
+
+void testOveraligned() {
+ auto *p = new OveralignedS;
+ p = new ((std::align_val_t)8) OveralignedS;
+ delete p;
+ p = new (std::nothrow) OveralignedS;
+
+ auto *pa = new OveralignedS[4];
+ pa = new ((std::align_val_t)8) OveralignedS[4];
+ delete[] pa;
+ pa = new (std::nothrow) OveralignedS[4];
+ // No error here since it is not calling a replaceable allocation function.
+ p = new ((std::align_val_t)8, 10LL) OveralignedS;
+}
+
+#ifdef NO_ERRORS
+// expected-no-diagnostics
+#else
+// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}}
+// expected-note@-17 {{if you supply your own aligned allocation functions}}
+// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-19 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}}
+// expected-note@-21 {{if you supply your own aligned allocation functions}}
+// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-23 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-25 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}}
+// expected-note@-27 {{if you supply your own aligned allocation functions}}
+// expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}}
+// expected-note@-29 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-29 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}}
+// expected-note@-30 {{if you supply your own aligned allocation functions}}
+// expected-error@-31 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-32 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-33 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' possibly unavailable on}}
+// expected-note@-34 {{if you supply your own aligned allocation functions}}
+// expected-error@-35 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-36 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-37 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' possibly unavailable on}}
+// expected-note@-38 {{if you supply your own aligned allocation functions}}
+
+// expected-error@-39 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}}
+// expected-note@-40 {{if you supply your own aligned allocation functions}}
+// expected-error@-41 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' possibly unavailable on}}
+// expected-note@-42 {{if you supply your own aligned allocation functions}}
+
+#endif
+
+// No errors if user-defined aligned allocation functions are available.
+void *operator new(std::size_t __sz, std::align_val_t) {
+ static char array[256];
+ return &array;
+}
+
+void operator delete(void *p, std::align_val_t) {
+}
+
+void testOveraligned2() {
+ auto p = new ((std::align_val_t)8) OveralignedS;
+ delete p;
+}
diff --git a/test/SemaCXX/warn-throw-out-noexcept-func.cpp b/test/SemaCXX/warn-throw-out-noexcept-func.cpp
index dfd1ff9065ab9..fc2919a1e327a 100644
--- a/test/SemaCXX/warn-throw-out-noexcept-func.cpp
+++ b/test/SemaCXX/warn-throw-out-noexcept-func.cpp
@@ -253,6 +253,43 @@ void with_try_block1() noexcept try { //expected-note {{non-throwing function de
} catch (char *) {
}
+namespace derived {
+struct B {};
+struct D: B {};
+void goodPlain() noexcept {
+ try {
+ throw D();
+ } catch (B) {}
+}
+void goodReference() noexcept {
+ try {
+ throw D();
+ } catch (B &) {}
+}
+void goodPointer() noexcept {
+ D d;
+ try {
+ throw &d;
+ } catch (B *) {}
+}
+void badPlain() noexcept { // expected-note {{non-throwing function declare here}}
+ try {
+ throw B(); // expected-warning {{'badPlain' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D) {}
+}
+void badReference() noexcept { // expected-note {{non-throwing function declare here}}
+ try {
+ throw B(); // expected-warning {{'badReference' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D &) {}
+}
+void badPointer() noexcept { // expected-note {{non-throwing function declare here}}
+ B b;
+ try {
+ throw &b; // expected-warning {{'badPointer' has a non-throwing exception specification but can still throw, resulting in unexpected program termination}}
+ } catch (D *) {}
+}
+}
+
int main() {
R1_ShouldDiag<int> o; //expected-note {{in instantiation of member function}}
S1_ShouldDiag<int> b; //expected-note {{in instantiation of member function}}