xref: /aosp_15_r20/external/clang/test/SemaTemplate/instantiate-try-catch.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -std=c++11 -verify %s
2*67e74705SXin Li 
3*67e74705SXin Li template<typename T> struct TryCatch0 {
fTryCatch04*67e74705SXin Li   void f() {
5*67e74705SXin Li     try {
6*67e74705SXin Li     } catch (T&&) { // expected-error 2{{cannot catch exceptions by rvalue reference}}
7*67e74705SXin Li     }
8*67e74705SXin Li   }
9*67e74705SXin Li };
10*67e74705SXin Li 
11*67e74705SXin Li template struct TryCatch0<int&>; // okay
12*67e74705SXin Li template struct TryCatch0<int&&>; // expected-note{{instantiation}}
13*67e74705SXin Li template struct TryCatch0<int>; // expected-note{{instantiation}}
14*67e74705SXin Li 
15*67e74705SXin Li 
16*67e74705SXin Li namespace PR10232 {
17*67e74705SXin Li   template <typename T>
18*67e74705SXin Li   class Templated {
19*67e74705SXin Li     struct Exception {
20*67e74705SXin Li     private:
21*67e74705SXin Li       Exception(const Exception&); // expected-note{{declared private here}}
22*67e74705SXin Li     };
exception()23*67e74705SXin Li     void exception() {
24*67e74705SXin Li       try {
25*67e74705SXin Li       } catch(Exception e) {  // expected-error{{calling a private constructor of class 'PR10232::Templated<int>::Exception'}}
26*67e74705SXin Li       }
27*67e74705SXin Li     }
28*67e74705SXin Li   };
29*67e74705SXin Li 
30*67e74705SXin Li   template class Templated<int>; // expected-note{{in instantiation of member function 'PR10232::Templated<int>::exception' requested here}}
31*67e74705SXin Li }
32