1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s -fexceptions -fcxx-exceptions -Wno-unevaluated-expression
2 
3 void f(); // expected-note {{possible target for call}}
4 void f(int); // expected-note {{possible target for call}}
5 
g()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));
9 }
10 
11 struct S {
12   void g(); // expected-note {{possible target for call}}
13   void g(int); // expected-note {{possible target for call}}
14 
hS15   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));
18   }
19 };
20 
stmt_expr()21 void stmt_expr() {
22   static_assert(noexcept(({ 0; })));
23 
24   static_assert(!noexcept(({ throw 0; })));
25 
26   static_assert(noexcept(({
27     try {
28       throw 0;
29     } catch (...) {
30     }
31     0;
32   })));
33 
34   static_assert(!noexcept(({
35     try {
36       throw 0;
37     } catch (...) {
38       throw;
39     }
40     0;
41   })));
42 
43   static_assert(!noexcept(({
44     try {
45       throw 0;
46     } catch (int) {
47     }
48     0;
49   })));
50 
51   static_assert(!noexcept(({
52     if (false) throw 0;
53   })));
54 
55   static_assert(noexcept(({
56     if constexpr (false) throw 0;
57   })));
58 
59   static_assert(!noexcept(({
60     if constexpr (false) throw 0; else throw 1;
61   })));
62 
63   static_assert(noexcept(({
64     if constexpr (true) 0; else throw 1;
65   })));
66 }
67 
vla(bool b)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}), "");
77 }
78 
79 struct pr_44514 {
80   // expected-error@+1{{value of type 'void' is not contextually convertible to 'bool'}}
81   void foo(void) const &noexcept(f());
82 };
83