Bug 36147

Summary: const function pointer leads to: warning: function called through a non-compatible type
Product: Sisyphus Reporter: Ivan Zakharyaschev <imz>
Component: gcc8Assignee: Gleb F-Malinovskiy <glebfm>
Status: NEW --- QA Contact: qa-sisyphus
Severity: minor    
Priority: P3 CC: glebfm, iv, vseleznv
Version: unstable   
Hardware: all   
OS: Linux   

Description Ivan Zakharyaschev 2019-02-21 14:15:27 MSK
gcc8-8.2.1-alt5.x86_64

When compiling rpm-build (from Sisyphus), we see warnings like:

interdep.c: In function 'makeReq1':
interdep.c:116:8: warning: function called through a non-compatible type
        hge(pkg1->header, RPMTAG_REQUIRENAME, NULL, (void **) &reqNv, &c) &&
        ^~~
interdep.c:117:8: warning: function called through a non-compatible type
        hge(pkg1->header, RPMTAG_REQUIREVERSION, NULL, (void **) &reqVv, NULL) &&
        ^~~
interdep.c:118:8: warning: function called through a non-compatible type
        hge(pkg1->header, RPMTAG_REQUIREFLAGS, NULL, (void **) &reqFv, NULL);
        ^~~

where the source code is like this:

    const HGE_t hge = (HGE_t)headerGetEntryMinMemory;
    int ok =
       hge(pkg1->header, RPMTAG_REQUIRENAME, NULL, (void **) &reqNv, &c) &&
       hge(pkg1->header, RPMTAG_REQUIREVERSION, NULL, (void **) &reqVv, NULL) &&
       hge(pkg1->header, RPMTAG_REQUIREFLAGS, NULL, (void **) &reqFv, NULL);

Removing the const qualifier makes the warning go away.

Isn't it a strange reason to give a warning in this case?

The const qualifier should affect just the variable where the pointer is stored and not the type of the function.