Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / compilerplugins / clang / test / classmemaccess.cxx
blob05bb457f87e3ce04aeb09383a7ce5077c667d4ac
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 <cstring>
12 void f(struct Incomplete* p1, struct S* p2);
14 struct S
16 S();
19 void f(struct Incomplete* p1, struct S* p2)
21 S s;
22 // expected-error@+1 {{writing to an object of non-trivial type 'S'; use assignment instead [loplugin:classmemaccess]}}
23 std::memset(&s, 0, sizeof s);
24 // expected-error@+1 {{writing to an object of non-trivial type 'S'; use assignment instead [loplugin:classmemaccess]}}
25 std::memset(static_cast<void*>(&s), 0, sizeof s);
26 auto const disableWarning = static_cast<void*>(&s);
27 std::memset(disableWarning, 0, sizeof s);
28 S a[1][1];
29 // expected-error@+1 {{writing to an object of non-trivial type 'S'; use assignment instead [loplugin:classmemaccess]}}
30 std::memset(a, 0, sizeof a);
31 std::memset(p1, 0, 10); // conservatively assume Incomplete may be trivial
32 // expected-error@+1 {{writing to an object of non-trivial type 'S'; use assignment instead [loplugin:classmemaccess]}}
33 std::memset(p2, 0, 10);
36 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */