1#include <QtCore/QDebug> 2#include <QtGui/QColor> 3 4 5 6struct Trivial { 7 int a; 8}; 9 10struct NonTrivial { 11 NonTrivial() {} 12 NonTrivial(const NonTrivial &) {} 13 void constFunction() const {}; 14 void nonConstFunction() {}; 15 int a; 16}; 17 18void by_pointer(NonTrivial*) {} 19void by_const_pointer(const NonTrivial*) {} 20void by_ref(NonTrivial&) {} 21void by_constRef(const NonTrivial&) {} 22 23int foo1(const Trivial nt) // Test #1: No warning 24{ 25 return nt.a; 26} 27 28int foo2(const NonTrivial nt) // Test #2: Warning 29{ 30 nt.constFunction(); 31 return nt.a; 32} 33 34int foo3(NonTrivial nt) // Test #3: Warning 35{ 36 return nt.a; 37} 38 39int foo4(NonTrivial nt) // Test #4: Warning 40{ 41 return nt.a; 42} 43 44int foo5(NonTrivial nt) // Test #5: No warning 45{ 46 by_pointer(&nt); 47 return nt.a; 48} 49 50 51int foo6(NonTrivial nt) // Test #6: No warning 52{ 53 by_ref(nt); 54 return nt.a; 55} 56 57int foo7(NonTrivial nt) // Test #7: No warning 58{ 59 nt.nonConstFunction(); 60 return nt.a; 61} 62 63int foo8(NonTrivial nt) // Test #8: Warning 64{ 65 nt.constFunction(); 66 return nt.a; 67} 68 69int foo9(NonTrivial nt) // Test #9: Warning 70{ 71 by_constRef(nt); 72 return nt.a; 73} 74 75int foo10(NonTrivial nt) // Test #10: Warning 76{ 77 by_const_pointer(&nt); 78 return nt.a; 79} 80 81int foo11(QColor) // Test #11: No warning 82{ 83 return 1; 84} 85 86int foo12(NonTrivial nt) // Test #12: No warning 87{ 88 nt = NonTrivial(); 89 return 1; 90} 91 92void func(QString text) 93{ 94 QTextStream a(&text); // OK, by-pointer to a CTOR 95} 96 97struct StringConstPtr 98{ 99 StringConstPtr(const QString *s) {} 100}; 101 102void func2(QString text) 103{ 104 StringConstPtr s(&text); // Warning, it's a const ptr 105} 106 107enum Option { 108 FooOption, 109 FooOption2 110}; 111 112 113Q_DECLARE_FLAGS(Options, Option) 114Q_DECLARE_OPERATORS_FOR_FLAGS(Options) 115 116struct NoUserCtorsButNotTrivial 117{ 118 NonTrivial t; 119}; 120 121void testNoUserCtorsButNotTrivial(NoUserCtorsButNotTrivial) 122{ 123 124} 125 126struct TrivialWithDefaultCopyCtorAndDtor 127{ 128 TrivialWithDefaultCopyCtorAndDtor(const TrivialWithDefaultCopyCtorAndDtor &) = default; 129 ~TrivialWithDefaultCopyCtorAndDtor() = default; 130 int m; 131}; 132 133void testTrivialWithDefaultCopyCtorAndDtor(TrivialWithDefaultCopyCtorAndDtor) 134{ 135 136} 137 138struct DefaultButNotTrivialCopyable 139{ 140 DefaultButNotTrivialCopyable(const DefaultButNotTrivialCopyable & ) = default; 141 ~DefaultButNotTrivialCopyable() = default; 142 NonTrivial t; 143}; 144 145void testDefaultButNotTrivialCopyable(DefaultButNotTrivialCopyable) 146{ 147 148} 149 150void shouldBeByValue(Trivial nt) 151{ 152 153} 154 155 156void isOK(const NonTrivial &&) 157{ 158} 159 160void foo(const Trivial &t = Trivial()); 161void foo1(const Trivial & = Trivial()); 162void foo2(const Trivial &t); 163void foo3(const Trivial&); 164 165void foo4(Trivial t); 166void foo4(Trivial t) 167{ 168} 169 170void foo5(Trivial t) 171{ 172} 173 174void foo6(Trivial t = {}) 175{ 176} 177 178 179struct Base // Test that fixits fix both Base and Derived 180{ 181 void foo(Trivial ); 182}; 183 184void Base::foo(Trivial ) 185{ 186} 187 188struct Derived : public Base 189{ 190 void foo(Trivial ); 191}; 192 193void Derived::foo(Trivial ) 194{ 195} 196 197struct QDBusMessage 198{ 199 void createErrorReply(QString) {} 200}; 201 202struct DeletedCtor // bug #360112 203{ 204 Q_DISABLE_COPY(DeletedCtor) 205}; 206 207struct CopyCtor // bug #360112 208{ 209 CopyCtor(const CopyCtor &) {} 210}; 211 212struct Ctors 213{ 214 Ctors (NonTrivial) {} 215}; 216 217void trivialByConstRef(int t) {} // Warn 218void trivialByRef(int &t) {} // OK 219 220// #381812 221 222class BaseWithVirtuals 223{ 224public: 225 virtual void virtualMethod1(const Trivial &) {}; // Warn 226 virtual void virtualMethod2(const Trivial &) {}; // Warn 227 void nonVirtualMethod(Trivial ) {}; // Warn 228}; 229 230class DerivedWithVirtuals : BaseWithVirtuals { 231public: 232 void virtualMethod1(const Trivial &) override {}; // OK 233 void virtualMethod2(const Trivial &) {}; // OK 234 void nonVirtualMethod(Trivial ) {}; // Warn 235}; 236 237 238// bug #403088 239void func(const std::atomic<int> &a) {} // Ok, since it's not trivially-copyable 240 241// generalization of bug #403088 242struct DeletedCopyCtor { 243 DeletedCopyCtor(const DeletedCopyCtor &) = delete; 244 int v; 245}; 246 247void func(const DeletedCopyCtor &a) {} 248