Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/coproc.h:230:46: clearing an object of non-trivial type ‘struct PCI_INFO’; use assignment or value-initialization instead [-Wclass-memaccess] #3245

Closed
smoe opened this issue Aug 9, 2019 · 6 comments

Comments

@smoe
Copy link
Contributor

smoe commented Aug 9, 2019

Hello,
I just backported 7.16.1 and saw myriads of the following compiler warning.
Cheers,
Steffen

/usr/local/bin/g++ -DHAVE_CONFIG_H -I. -I..  -I.. -I../api -I../db -I../lib -I../lib/mac -I../sched -I../tools -I../vda -pthread -I/usr/include/mariadb -I/usr/include/mariadb/mysql -pthread -Wdate-time -D_FORTIFY_SOURCE=2  -Wall -Wextra -Wshadow -Wredundant-decls -Wdisabled-optimization -Wpointer-arith -Wstrict-aliasing -Wcast-align  -g -O2 -fdebug-prefix-map=/home/moeller/boinc/boinc-7.16.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wall -O3 -funroll-loops -fforce-addr -ffast-math -flto -Wall -c -o sample_bitwise_validator.o sample_bitwise_validator.cpp
In file included from ../lib/hostinfo.h:32,
                 from sched_limit.h:25,
                 from sched_config.h:25,
                 from validator.h:18,
                 from sample_bitwise_validator.cpp:35:
../lib/coproc.h: In member function ‘void COPROC::clear()’:
../lib/coproc.h:230:46: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct PCI_INFO’; use assignment or value-initialization instead [-Wclass-memaccess]
         memset(&pci_info, 0, sizeof(pci_info));
                                              ^
../lib/coproc.h:133:8: note: ‘struct PCI_INFO’ declared here
 struct PCI_INFO {
        ^~~~~~~~
@smoe
Copy link
Contributor Author

smoe commented Aug 9, 2019

Ah - same here:

In file included from ../lib/gui_rpc_client.h:52,
                 from screensaver_x11.cpp:41:
../lib/prefs.h: In member function ‘void WEEK_PREFS::clear()’:
../lib/prefs.h:108:43: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct WEEK_PREFS’; use assignment or value-initialization instead [-Wclass-memaccess]
         memset(this, 0, sizeof(WEEK_PREFS));
                                           ^
../lib/prefs.h:104:8: note: ‘struct WEEK_PREFS’ declared here
 struct WEEK_PREFS {
        ^~~~~~~~~~

@AenBleidd
Copy link
Member

AenBleidd commented Aug 9, 2019 via email

@smoe
Copy link
Contributor Author

smoe commented Aug 9, 2019

Not today - was only "quickly" procastinating into rolling 7.16.1 on one of my machines. Will address them over the weekend.

@oppiet30
Copy link

There is a lot more than just that one.
boinc_compile_warnings.txt

@oppiet30
Copy link

Oppie> It's telling you the class is not a plain-old C struct anymore because
you added a constructor. So memset could blow-away your class's data. There
are lots of valid ways to deal with this, including just ignoring the warning.
In general, memset is wrong. But C coders can't let it go. Anyway, here's the
fix:

// bad
memset(&pci_info, 0, sizeof(pci_info));

// good
pci_info = PCI_INFO{};

@AenBleidd
Copy link
Member

Fixed via #3364

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants