https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84166

            Bug ID: 84166
           Summary: Wrong warning message emitted for loss of qualifiers
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ttsiodras at gmail dot com
  Target Milestone: ---

The code shown below...

    #include <stdlib.h>
    #include <stdint.h>

    extern void get_buffer_from_HW_driver(volatile uint32_t **p);

    void getBuffer(volatile uint32_t **pp)
    {
        // Write an address into p, that is obtained from a driver
        // The underlying HW will be DMA-ing into this address,
        // so the data pointed-to by the pointer returned by this
        // call are volatile.
        get_buffer_from_HW_driver(pp);
    }

    void work()
    {
        uint32_t *p = NULL;
        getBuffer((volatile uint32_t **)&p);
    }

...is erroneously forgetting to set the `volatile` qualifier for the pointer
`p` declared in `work`. Unfortunately, GCC's related warning indicates that
there is a missing `const` - instead of a missing `volatile`:

    $ gcc -c -Wall -Wextra -Wcast-qual constqual.c

    constqual.c: In function ‘work’:
    constqual.c:20:15: warning: to be safe all intermediate pointers in cast
from 
                   ‘uint32_t ** {aka unsigned int **}’ to ‘volatile uint32_t ** 
                   {aka volatile unsigned int **}’ must be ‘const’ qualified
                   [-Wcast-qual]
     getBuffer((volatile uint32_t **)&p);
           ^

It appears that GCC confuses `const` with `volatile` here.

Reply via email to