Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaCXX / cxx0x-noexcept-expression.cpp
blobc2b2244c117a09bc3afd08b484b1d3cd43899831
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression -fexperimental-new-constant-interpreter
4 void f(); // expected-note {{possible target for call}}
5 void f(int); // expected-note {{possible target for call}}
7 void g() {
8 bool b = noexcept(f); // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
9 bool b2 = noexcept(f(0));
12 struct S {
13 void g(); // expected-note {{possible target for call}}
14 void g(int); // expected-note {{possible target for call}}
16 void h() {
17 bool b = noexcept(this->g); // expected-error {{reference to non-static member function must be called; did you mean to call it with no arguments?}}
18 bool b2 = noexcept(this->g(0));
22 void stmt_expr() {
23 static_assert(noexcept(({ 0; })));
25 static_assert(!noexcept(({ throw 0; })));
27 static_assert(noexcept(({
28 try {
29 throw 0;
30 } catch (...) {
33 })));
35 static_assert(!noexcept(({
36 try {
37 throw 0;
38 } catch (...) {
39 throw;
42 })));
44 static_assert(!noexcept(({
45 try {
46 throw 0;
47 } catch (int) {
50 })));
52 static_assert(!noexcept(({
53 if (false) throw 0;
54 })));
56 static_assert(noexcept(({
57 if constexpr (false) throw 0;
58 })));
60 static_assert(!noexcept(({
61 if constexpr (false) throw 0; else throw 1;
62 })));
64 static_assert(noexcept(({
65 if constexpr (true) 0; else throw 1;
66 })));
69 void vla(bool b) { // expected-note 5{{declared here}}
70 static_assert(noexcept(static_cast<int(*)[true ? 41 : 42]>(0)), "");
71 // FIXME: This can't actually throw, but we conservatively assume any VLA
72 // type can throw for now.
73 static_assert(!noexcept(static_cast<int(*)[b ? 41 : 42]>(0)), ""); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
74 expected-note {{function parameter 'b' with unknown value cannot be used in a constant expression}}
75 static_assert(!noexcept(static_cast<int(*)[b ? throw : 42]>(0)), ""); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
76 expected-note {{function parameter 'b' with unknown value cannot be used in a constant expression}}
77 static_assert(!noexcept(reinterpret_cast<int(*)[b ? throw : 42]>(0)), ""); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
78 expected-note {{function parameter 'b' with unknown value cannot be used in a constant expression}}
79 static_assert(!noexcept((int(*)[b ? throw : 42])0), ""); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
80 expected-note {{function parameter 'b' with unknown value cannot be used in a constant expression}}
81 static_assert(!noexcept((int(*)[b ? throw : 42]){0}), ""); // expected-warning {{variable length arrays in C++ are a Clang extension}} \
82 expected-note {{function parameter 'b' with unknown value cannot be used in a constant expression}}
85 struct pr_44514 {
86 // expected-error@+1{{value of type 'void' is not implicitly convertible to 'bool'}}
87 void foo(void) const &noexcept(f());
90 namespace P1401 {
91 const int *ptr = nullptr;
92 void f() noexcept(sizeof(char[2])); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
93 void g() noexcept(sizeof(char));
94 void h() noexcept(ptr); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
95 void i() noexcept(nullptr); // expected-error {{conversion from 'std::nullptr_t' to 'bool' is not allowed in a converted constant expression}}
96 void j() noexcept(0);
97 void k() noexcept(1);
98 void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
99 } // namespace P1401