A: a new bug to old plain C

LIU Hao lh_mouse@126.com
Wed Nov 26 10:22:21 GMT 2025


在 2025-11-26 18:12, Александр Поваляев 写道:
> [[[Aleksandr]]] So these types are not compatible. But the assignment goes without any error or warning.

Because you have asked someone to quote the standard, so you must think in the standard way.

Compatible types has nothing to do with any error or warnings. If two types are compatible, then they can 
be re-interpreted as each other without conversion.

These two variables are also of incompatible types, but nevertheless, they can be assigned to each other:

    int a = 1;
    float b = 2;
    a = b;   // conversion happens
    b = a;   // conversion happens


>     But the conversion is allowed by the second quoted paragraph. Although those pointers point to
>     incompatible types, the conversion happens as a simple assignment, so qualified compatible types are
>     also
>     allowed. (The left operand can't have fewer qualifiers than the right operand.)
> 
> [[[Aleksandr]]] What particular citation do you mean?

See this:

    6.5.17 Assignment operators
    6.5.17.2 Simple assignment

    1 One of the following shall hold

      — the left operand has atomic, qualified, or unqualified pointer type, and
        (considering the type the left operand would have after lvalue conversion)
        both operands are pointers to >>>>>>> qualified or unqualified versions of
        compatible types <<<<<<<, and the type pointed to by the left operand has all
        the qualifiers of the type pointed to by the right operand;


> [[[Aleksandr]]] Also. An important point to be mentioned: "Foo**"->"const Foo * const * const" conversion 
> being compiled with "-Wno-incompatible-pointer-types" still produce an error :(

It's because they don't point to qualified compatible types. If you remove top-level * (to undo 'point 
to'), then also remove top-level `const` (to undo 'qualified'), you get are `Foo *` and `const Foo *`, 
and they are clearly not compatible.


-- 
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20251126/8ff4dda3/attachment-0001.sig>


More information about the Gcc-help mailing list