linux-usb-gadgets / libusbgx

C library encapsulating the Linux kernel USB gadget configfs userspace API functionality
GNU General Public License v2.0
216 stars 72 forks source link

Can't include usbg/function/ms.h from c++ source #26

Closed studiofuga closed 6 years ago

studiofuga commented 6 years ago

Environment

Ubuntu Linux 16.04, up to date.

$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.6) 5.4.0 20160609

Simply #including usbg/function/ms.h in a c++ file breaks the compilation, due to different handling of casting to unions in inlined functions.

#include <usbg/function/ms.h>
int main()
{
    return 0;
}

Expected result

Program compiles correctly like with gcc:

$ gcc -I ../include/ -o test test.c
$

Result

Program doesn't compile with g++:

In file included from test.cpp:1:0:
../include/usbg/function/ms.h: In function ‘int usbg_f_ms_set_lun_cdrom(usbg_f_ms*, int, bool)’:
../include/usbg/function/ms.h:179:38: error: no matching function for call to ‘usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(bool&)’
        (union usbg_f_ms_lun_attr_val)cdrom);
                                      ^
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val()
 union usbg_f_ms_lun_attr_val {
       ^
../include/usbg/function/ms.h:51:7: note:   candidate expects 0 arguments, 1 provided
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const usbg_f_ms_lun_attr_val&)
../include/usbg/function/ms.h:51:7: note:   no known conversion for argument 1 from ‘bool’ to ‘const usbg_f_ms_lun_attr_val&’
../include/usbg/function/ms.h: In function ‘int usbg_f_ms_set_lun_ro(usbg_f_ms*, int, bool)’:
../include/usbg/function/ms.h:205:38: error: no matching function for call to ‘usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(bool&)’
        (union usbg_f_ms_lun_attr_val)ro);
                                      ^
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val()
 union usbg_f_ms_lun_attr_val {
       ^
../include/usbg/function/ms.h:51:7: note:   candidate expects 0 arguments, 1 provided
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const usbg_f_ms_lun_attr_val&)
../include/usbg/function/ms.h:51:7: note:   no known conversion for argument 1 from ‘bool’ to ‘const usbg_f_ms_lun_attr_val&’
../include/usbg/function/ms.h: In function ‘int usbg_f_ms_set_lun_nofua(usbg_f_ms*, int, bool)’:
../include/usbg/function/ms.h:235:38: error: no matching function for call to ‘usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(bool&)’
        (union usbg_f_ms_lun_attr_val)nofua);
                                      ^
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val()
 union usbg_f_ms_lun_attr_val {
       ^
../include/usbg/function/ms.h:51:7: note:   candidate expects 0 arguments, 1 provided
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const usbg_f_ms_lun_attr_val&)
../include/usbg/function/ms.h:51:7: note:   no known conversion for argument 1 from ‘bool’ to ‘const usbg_f_ms_lun_attr_val&’
../include/usbg/function/ms.h: In function ‘int usbg_f_ms_set_lun_removable(usbg_f_ms*, int, bool)’:
../include/usbg/function/ms.h:263:38: error: no matching function for call to ‘usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(bool&)’
        (union usbg_f_ms_lun_attr_val)removable);
                                      ^
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val()
 union usbg_f_ms_lun_attr_val {
       ^
../include/usbg/function/ms.h:51:7: note:   candidate expects 0 arguments, 1 provided
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const usbg_f_ms_lun_attr_val&)
../include/usbg/function/ms.h:51:7: note:   no known conversion for argument 1 from ‘bool’ to ‘const usbg_f_ms_lun_attr_val&’
../include/usbg/function/ms.h: In function ‘int usbg_f_ms_set_lun_file(usbg_f_ms*, int, const char*)’:
../include/usbg/function/ms.h:309:38: error: no matching function for call to ‘usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const char*&)’
        (union usbg_f_ms_lun_attr_val)file);
                                      ^
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val()
 union usbg_f_ms_lun_attr_val {
       ^
../include/usbg/function/ms.h:51:7: note:   candidate expects 0 arguments, 1 provided
../include/usbg/function/ms.h:51:7: note: candidate: usbg_f_ms_lun_attr_val::usbg_f_ms_lun_attr_val(const usbg_f_ms_lun_attr_val&)
../include/usbg/function/ms.h:51:7: note:   no known conversion for argument 1 from ‘const char*’ to ‘const usbg_f_ms_lun_attr_val&’
$

Version affected

commit 9e71df567e5e489419a7095f2885f64ffff4e058

Workaround

Add a proper #if instruction to remove the offending functions when compiling in c++

kopasiak commented 6 years ago

I know the problem. It's common among many function headers. I'm in the middle of fixing this but I have been preempted by other task. I'll post a fix as soon as possible

studiofuga commented 6 years ago

Thanks for the feedback. If you want to share the strategy for fixing, I would be pleased to sketch a patch on this. Bye

kopasiak commented 6 years ago

It was pretty the same in all headers so no need to split this work but you are welcomed with any other patches;)

I've just fixed the issue in master branch. Please check if it works for you.

studiofuga commented 6 years ago

It works like a charm, many thanks!