Warning, /sdk/clazy/tests/function-args-by-value/main.cpp.fixed.expected is written in an unsupported language. File is not indexed.

0001 #include <QtCore/QDebug>
0002 #include <QtGui/QColor>
0003 #include <atomic>
0004 
0005 
0006 struct Trivial {
0007     int a;
0008 };
0009 
0010 struct NonTrivial {
0011     NonTrivial() {}
0012     NonTrivial(const NonTrivial &) {}
0013     void constFunction() const {};
0014     void nonConstFunction() {};
0015     int a;
0016 };
0017 
0018 void by_pointer(NonTrivial*) {}
0019 void by_const_pointer(const NonTrivial*) {}
0020 void by_ref(NonTrivial&) {}
0021 void by_constRef(const NonTrivial&) {}
0022 
0023 int foo1(const Trivial nt) // Test #1: No warning
0024 {
0025     return nt.a;
0026 }
0027 
0028 int foo2(const NonTrivial nt) // Test #2: Warning
0029 {
0030     nt.constFunction();
0031     return nt.a;
0032 }
0033 
0034 int foo3(NonTrivial nt) // Test #3: Warning
0035 {
0036     return nt.a;
0037 }
0038 
0039 int foo4(NonTrivial nt) // Test #4: Warning
0040 {
0041     return nt.a;
0042 }
0043 
0044 int foo5(NonTrivial nt) // Test #5: No warning
0045 {
0046     by_pointer(&nt);
0047     return nt.a;
0048 }
0049 
0050 
0051 int foo6(NonTrivial nt) // Test #6: No warning
0052 {
0053     by_ref(nt);
0054     return nt.a;
0055 }
0056 
0057 int foo7(NonTrivial nt) // Test #7: No warning
0058 {
0059     nt.nonConstFunction();
0060     return nt.a;
0061 }
0062 
0063 int foo8(NonTrivial nt) // Test #8: Warning
0064 {
0065     nt.constFunction();
0066     return nt.a;
0067 }
0068 
0069 int foo9(NonTrivial nt) // Test #9: Warning
0070 {
0071     by_constRef(nt);
0072     return nt.a;
0073 }
0074 
0075 int foo10(NonTrivial nt) // Test #10: Warning
0076 {
0077     by_const_pointer(&nt);
0078     return nt.a;
0079 }
0080 
0081 int foo11(QColor) // Test #11: No warning
0082 {
0083     return 1;
0084 }
0085 
0086 int foo12(NonTrivial nt) // Test #12: No warning
0087 {
0088     nt = NonTrivial();
0089     return 1;
0090 }
0091 
0092 void func(QString text)
0093 {
0094     QTextStream a(&text); // OK, by-pointer to a CTOR
0095 }
0096 
0097 struct StringConstPtr
0098 {
0099     StringConstPtr(const QString *s) {}
0100 };
0101 
0102 void func2(QString text)
0103 {
0104     StringConstPtr s(&text); // Warning, it's a const ptr
0105 }
0106 
0107 enum Option {
0108     FooOption,
0109     FooOption2
0110 };
0111 
0112 
0113 Q_DECLARE_FLAGS(Options, Option)
0114 Q_DECLARE_OPERATORS_FOR_FLAGS(Options)
0115 
0116 struct NoUserCtorsButNotTrivial
0117 {
0118     NonTrivial t;
0119 };
0120 
0121 void testNoUserCtorsButNotTrivial(NoUserCtorsButNotTrivial)
0122 {
0123 
0124 }
0125 
0126 struct TrivialWithDefaultCopyCtorAndDtor
0127 {
0128     TrivialWithDefaultCopyCtorAndDtor(const TrivialWithDefaultCopyCtorAndDtor &) = default;
0129     ~TrivialWithDefaultCopyCtorAndDtor() = default;
0130     int m;
0131 };
0132 
0133 void testTrivialWithDefaultCopyCtorAndDtor(TrivialWithDefaultCopyCtorAndDtor)
0134 {
0135 
0136 }
0137 
0138 struct DefaultButNotTrivialCopyable
0139 {
0140     DefaultButNotTrivialCopyable(const DefaultButNotTrivialCopyable & ) = default;
0141     ~DefaultButNotTrivialCopyable() = default;
0142     NonTrivial t;
0143 };
0144 
0145 void testDefaultButNotTrivialCopyable(DefaultButNotTrivialCopyable)
0146 {
0147 
0148 }
0149 
0150 void shouldBeByValue(Trivial nt)
0151 {
0152 
0153 }
0154 
0155 
0156 void isOK(const NonTrivial &&)
0157 {
0158 }
0159 
0160 void foo(const Trivial &t = Trivial());
0161 void foo1(const Trivial & = Trivial());
0162 void foo2(const Trivial &t);
0163 void foo3(const Trivial&);
0164 
0165 void foo4(Trivial t);
0166 void foo4(Trivial t)
0167 {
0168 }
0169 
0170 void foo5(Trivial t)
0171 {
0172 }
0173 
0174 void foo6(Trivial t = {})
0175 {
0176 }
0177 
0178 
0179 struct Base // Test that fixits fix both Base and Derived
0180 {
0181     void foo(Trivial );
0182 };
0183 
0184 void Base::foo(Trivial )
0185 {
0186 }
0187 
0188 struct Derived : public Base
0189 {
0190     void foo(Trivial );
0191 };
0192 
0193 void Derived::foo(Trivial )
0194 {
0195 }
0196 
0197 struct QDBusMessage
0198 {
0199     void createErrorReply(QString) {}
0200 };
0201 
0202 struct DeletedCtor // bug #360112
0203 {
0204     Q_DISABLE_COPY(DeletedCtor)
0205 };
0206 
0207 struct CopyCtor // bug #360112
0208 {
0209     CopyCtor(const CopyCtor &) {}
0210 };
0211 
0212 struct Ctors
0213 {
0214     Ctors (NonTrivial) {}
0215 };
0216 
0217 void trivialByConstRef(int t) {} // Warn
0218 void trivialByRef(int &t) {} // OK
0219 
0220 // #381812
0221 
0222 class BaseWithVirtuals
0223 {
0224 public:
0225     virtual void virtualMethod1(const Trivial &) {}; // Warn
0226     virtual void virtualMethod2(const Trivial &) {}; // Warn
0227     void nonVirtualMethod(Trivial ) {}; // Warn
0228 };
0229 
0230 class DerivedWithVirtuals : BaseWithVirtuals {
0231 public:
0232     void virtualMethod1(const Trivial &) override {}; // OK
0233     void virtualMethod2(const Trivial &) {}; // OK
0234     void nonVirtualMethod(Trivial ) {}; // Warn
0235 };
0236 
0237 
0238 // bug #403088
0239 void func(const std::atomic<int> &a) {} // Ok, since it's not trivially-copyable
0240 
0241 // generalization of bug #403088
0242 struct DeletedCopyCtor {
0243     DeletedCopyCtor(const DeletedCopyCtor &) = delete;
0244     int v;
0245 };
0246 
0247 void func(const DeletedCopyCtor &a) {}