tdf#130857 qt weld: Support "Insert Breaks" dialog
[LibreOffice.git] / compilerplugins / clang / test / unnecessarycatchthrow.cxx
bloba9b32d86fa84b067bdca5f675f81cea0f1ad2519
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <iostream>
11 #include <fstream>
13 void foo();
15 int main()
17 try {
18 foo();
19 } catch(int const &) { // expected-error {{unnecessary catch and throw [loplugin:unnecessarycatchthrow]}}
20 throw;
22 try {
23 foo();
24 } catch(int const & ex) { // expected-error {{unnecessary catch and throw [loplugin:unnecessarycatchthrow]}}
25 throw ex;
27 try {
28 foo();
29 } catch(int const &) {
30 std::cout << "test";
31 throw;
36 void test1()
38 // cannot remove catch/throw where the throw is of a non-final class
39 struct B {};
40 struct D: B {};
41 try {
42 throw D();
43 } catch (B & b) {
44 throw b; // must not be removed
48 void test2()
50 struct F final {};
51 try {
52 throw F();
53 } catch (F const & f) { // expected-error {{unnecessary catch and throw [loplugin:unnecessarycatchthrow]}}
54 throw f;
58 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */