-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.cc
94 lines (80 loc) · 1.84 KB
/
example.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2022 Cory Fields
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Warn about any function that calls into another function that returns
// an MaybeEarlyExit. The intention is to force _any_ returned MaybeEarlyExit to
// bubble all the way back up to main. Like manual exception catch/rethrowing.
#include "example.h"
MaybeEarlyExit<int> maybe_early_exit()
{
return {};
}
MaybeEarlyExit<> caller()
{
auto foo = maybe_early_exit();
struct quickstruct {
int m_val{0};
};
quickstruct tempstruct;
tempstruct.m_val = maybe_early_exit();
return {};
}
struct Object
{
};
MaybeEarlyExit<Object> ObjectCaller()
{
Object object{};
return object;
};
void caller2();
auto caller2() -> void;
void caller2() // should warn for not returning MaybeEarlyExit.
{
auto foo(maybe_early_exit());
const auto& bar = maybe_early_exit();
int castret{0};
castret = maybe_early_exit();
return; // should rewrite as "return {};".
}
void caller3() // should warn for not returning MaybeEarlyExit.
{
auto foo = maybe_early_exit();
if (maybe_early_exit()) {
return; // should rewrite as "return {};"
}
if (!maybe_early_exit()) {
return; // should rewrite as "return {};"
}
if (true) {
maybe_early_exit();
}
if (true) maybe_early_exit();
class fooclass{
void myfunc() { return; }
};
// Should add "return {};"
}
MaybeEarlyExit<> func(int arg)
{
return {};
}
void caller4()
{
using functype = MaybeEarlyExit<>(*)(int);
functype fpointer = func;
const auto& foo = fpointer(1);
}
void caller5()
{
maybe_early_exit();
}
void caller6()
{
Object object{};
object = ObjectCaller();
}
int caller7()
{
return maybe_early_exit();
}