-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclion_bugs.cpp
118 lines (103 loc) · 2.63 KB
/
clion_bugs.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "clion_bugs.h"
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
class Slice {
public:
Slice() = default;
template <size_t N>
Slice(const char (&a)[N]) : size(N) { // Can't resolve variable N
}
size_t size;
};
void f_slice(Slice slice) {
}
void bug_slice() {
f_slice("hello"); // Parameter type mismatch: Types 'Slice' and 'const char[6]' are not compatible
}
enum class ScopeExit {};
template <class FunctionT>
void operator+(ScopeExit, FunctionT &&func) {
}
void bug_scope_exit() {
ScopeExit() + [&] {}; // Binary operator '+' can't be applied to the expression of type ScopeExit and 'void (*)()'
}
class SfinaeBug {
public:
template <class T>
explicit SfinaeBug(T s, std::enable_if_t<std::is_same<int, T>::value, int> = 0) {
}
template <class T>
explicit SfinaeBug(T s, std::enable_if_t<!std::is_same<int, T>::value, int> =
0) // Duplicated declaration of constructor 'SfinaeBug'
{
}
};
void bug_class_in_function_() {
class A {
public:
A() = default; // explicit type is required here
};
class B {
public:
void f() {
std::make_unique<A>(); // Can't resolve variable A
}
};
}
class BugClassInFunctionInClass {
public:
private:
void f() {
}
void g() {
class C {
C(BugClassInFunctionInClass *b) {
b->f(); // Private 'BugClassInFunctionInClass::f()' is inaccessible
}
};
}
};
// Declarations of A::Object and B::Object must be in the header
namespace A {
class Object {};
} // namespace A
namespace B {
class Object {};
} // namespace B
void bug_with_header(const A::Object &) { // function 'bug_with_header' was redeclared with different type ...
}
void bug_with_header(const B::Object &) { // function 'bug_with_header' was redeclared with different type ...
}
class ClassWithoutDefaultConstructor {
public:
ClassWithoutDefaultConstructor(std::unique_ptr<int> x) : x_(std::move(x)) {
}
private:
std::unique_ptr<int> x_;
};
class ClassFieldWithoutDefaultConstructor {
public:
ClassFieldWithoutDefaultConstructor() { // field without_default must be initialized
}
private:
ClassWithoutDefaultConstructor without_default{nullptr};
};
void bug_lamda_with_default_argument() {
auto f = [](int a, int b = 1) {};
f(1); // Too few arguments, expected 2
};
void bug_lambda_return_string() {
auto f = [] {
return std::string("hello"); // Returning 'std::basic_string...' from lambda returning 'void'
};
}
void bug_vector() {
std::vector<int> a(1);
std::vector<int> b;
b.push_back(a.back()); // Parameter type mismatch: expression must be rvalue
};
int main() {
return 0;
}