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}}
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));
13 void g(); // expected-note {{possible target for call}}
14 void g(int); // expected-note {{possible target for call}}
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));
23 static_assert(noexcept(({ 0; })));
25 static_assert(!noexcept(({ throw 0; })));
27 static_assert(noexcept(({
35 static_assert(!noexcept(({
44 static_assert(!noexcept(({
52 static_assert(!noexcept(({
56 static_assert(noexcept(({
57 if constexpr (false) throw 0;
60 static_assert(!noexcept(({
61 if constexpr (false) throw 0; else throw 1;
64 static_assert(noexcept(({
65 if constexpr (true) 0; else throw 1;
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
}}
86 // expected-error@+1{{value of type 'void' is not implicitly convertible to 'bool'}}
87 void foo(void) const &noexcept(f());
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}}
98 void l() noexcept(2); // expected-error {{noexcept specifier argument evaluates to 2, which cannot be narrowed to type 'bool'}}