Issue 179454
Summary Clang emits only a warning for nested pointer qualifier mismatch (uint32_t **** → const uint32_t ****)
Labels clang
Assignees
Reporter pengyuxiao
    Clang accepts the following assignment between incompatible pointer types by issuing only a warning, which allows compilation to succeed and an executable to be produced:
    LHS type: const uint32_t ****
    RHS type: uint32_t ****
This is a nested pointer qualification mismatch: the const qualifier is not applied at the first level of indirection, therefore the two pointer types are not compatible. Despite that, Clang reports the issue as a warning (-Wincompatible-pointer-types-discards-qualifiers) and continues compilation.GCC rejects the same assignment as an error in strict modes, which aligns with the expectation that this violates the C11 assignment constraints.

Minimal reproducible example:
#include <stdint.h>
uint32_t **g_820;
uint32_t ***g_819[6][3];
int main(void) {
    const uint32_t ****l_946[2];
    /* optional: make g_819 contain a value consistent with its element type */
    g_819[0][0] = &g_820;
    for (int i = 0; i < 2; i++) {
        l_946[i] = &g_819[5][2];   /* incompatible: uint32_t **** -> const uint32_t **** */
    }
    return 0;
}

clang version:Ubuntu clang version 22.0.0
Show the diagnostic:clang -std=c11 -Wall -Wextra -pedantic -fsyntax-only repro.c

Clang emits only a warning similar to:
warning: assigning to 'const uint32_t ****' from 'uint32_t ****' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers] and continues compilation, allowing code generation and linking to succeed.

Expected result:
Because the assignment violates the C11 constraint for assignment between pointers to compatible types (C11 §6.5.16.1), Clang should reject the program (i.e., treat it as an error by default, or at minimum under -pedantic-errors / strict conformance modes), rather than allowing a successful build that produces an executable.

C11 rationale:
According to ISO/IEC 9899:2011 (C11), §6.5.16.1, an assignment is only allowed if both operands are pointers to qualified or unqualified versions of compatible types. In C, uint32_t **** and const uint32_t **** are not compatible because the qualifier is not at the first level of indirection.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to