[clang-cl] Ignore /Wv and /Wv:17 flags
[llvm-project.git] / clang / test / SemaCXX / cxx0x-noexcept-expression.cpp
blobf4911541d1d33669cd43ba2582bb8914aed56eb8
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
3 void f(); // expected-note {{possible target for call}}
4 void f(int); // expected-note {{possible target for call}}
6 void g() {
7 bool b = noexcept(f); // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
8 bool b2 = noexcept(f(0));
11 struct S {
12 void g(); // expected-note {{possible target for call}}
13 void g(int); // expected-note {{possible target for call}}
15 void h() {
16 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?}}
17 bool b2 = noexcept(this->g(0));
21 void stmt_expr() {
22 static_assert(noexcept(({ 0; })));
24 static_assert(!noexcept(({ throw 0; })));
26 static_assert(noexcept(({
27 try {
28 throw 0;
29 } catch (...) {
32 })));
34 static_assert(!noexcept(({
35 try {
36 throw 0;
37 } catch (...) {
38 throw;
41 })));
43 static_assert(!noexcept(({
44 try {
45 throw 0;
46 } catch (int) {
49 })));
51 static_assert(!noexcept(({
52 if (false) throw 0;
53 })));
55 static_assert(noexcept(({
56 if constexpr (false) throw 0;
57 })));
59 static_assert(!noexcept(({
60 if constexpr (false) throw 0; else throw 1;
61 })));
63 static_assert(noexcept(({
64 if constexpr (true) 0; else throw 1;
65 })));
68 void vla(bool b) {
69 static_assert(noexcept(static_cast<int(*)[true ? 41 : 42]>(0)), "");
70 // FIXME: This can't actually throw, but we conservatively assume any VLA
71 // type can throw for now.
72 static_assert(!noexcept(static_cast<int(*)[b ? 41 : 42]>(0)), "");
73 static_assert(!noexcept(static_cast<int(*)[b ? throw : 42]>(0)), "");
74 static_assert(!noexcept(reinterpret_cast<int(*)[b ? throw : 42]>(0)), "");
75 static_assert(!noexcept((int(*)[b ? throw : 42])0), "");
76 static_assert(!noexcept((int(*)[b ? throw : 42]){0}), "");
79 struct pr_44514 {
80 // expected-error@+1{{value of type 'void' is not implicitly convertible to 'bool'}}
81 void foo(void) const &noexcept(f());
84 namespace P1401 {
85 const int *ptr = nullptr;
86 void f() noexcept(sizeof(char[2])); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
87 void g() noexcept(sizeof(char));
88 void h() noexcept(ptr); // expected-error {{conversion from 'const int *' to 'bool' is not allowed in a converted constant expression}}
89 void i() noexcept(nullptr); // expected-error {{conversion from 'std::nullptr_t' to 'bool' is not allowed in a converted constant expression}}
90 void j() noexcept(0);
91 void k() noexcept(1);
92 void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}
93 } // namespace P1401