[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / except / except.spec / p1.cpp
blob3b392632aed3011f6d208bf14ce6b134b2b6b6ee
1 // RUN: %clang_cc1 -std=c++11 -fexceptions -fcxx-exceptions -fsyntax-only -verify %s
3 // Simple parser tests, dynamic specification.
5 namespace dyn {
7 struct X { };
9 struct Y { };
11 void f() throw() { }
13 void g(int) throw(X) { }
15 void h() throw(X, Y) { }
17 class Class {
18 void foo() throw (X, Y) { }
21 void (*fptr)() throw();
25 // Simple parser tests, noexcept specification.
27 namespace noex {
29 void f1() noexcept { }
30 void f2() noexcept (true) { }
31 void f3() noexcept (false) { }
32 void f4() noexcept (1 < 2) { }
34 class CA1 {
35 void foo() noexcept { }
36 void bar() noexcept (true) { }
39 void (*fptr1)() noexcept;
40 void (*fptr2)() noexcept (true);
44 namespace mix {
46 void f() throw(int) noexcept { } // expected-error {{cannot have both}}
47 void g() noexcept throw(int) { } // expected-error {{cannot have both}}
51 // Sema tests, noexcept specification
53 namespace noex {
55 struct A {};
57 void g1() noexcept(A()); // expected-error {{value of type 'A' is not implicitly convertible to 'bool'}}
58 void g2(bool b) noexcept(b); // expected-error {{noexcept specifier argument is not a constant expression}} expected-note {{function parameter 'b' with unknown value}} expected-note {{here}}
61 namespace noexcept_unevaluated {
62 template<typename T> bool f(T) {
63 T* x = 1;
66 template<typename T>
67 void g(T x) noexcept((sizeof(T) == sizeof(int)) || noexcept(f(x))) { }
69 void h() {
70 g(1);
74 namespace PR11084 {
75 template <int X> struct A {
76 static int f() noexcept(1 / X) { return 10; } // expected-error{{noexcept specifier argument is not a constant expression}} expected-note{{division by zero}}
79 template<int X> void f() {
80 int (*p)() noexcept(1 / X); // expected-error{{noexcept specifier argument is not a constant expression}} expected-note{{division by zero}}
83 void g() {
84 A<0>::f(); // expected-note{{in instantiation of exception specification for 'f'}}
85 f<0>(); // expected-note{{in instantiation of function template specialization}}
89 namespace FuncTmplNoexceptError {
90 int a = 0;
91 // expected-error@+1{{noexcept specifier argument is not a constant expression}}
92 template <class T> T f() noexcept(a++){ return {};}
93 void g(){
94 f<int>();