Menu

#4006 Loss of qualifiers from pointer target is not reported in cases of array-to-pointer decay

open
nobody
None
other
5
2026-06-06
2026-06-06
No

1: Sample code that reproduces the problem.

struct SAC {
  char m[64];
};

char *str_from_struct(const struct SAC *pocs)
{
  // constraint violation: array to pointer decay does not remove const
  return pocs->m; // expected diagnostic is produced
}

char *str_from_array(const char (*paocc)[64])
{
  // constraint violation: array to pointer decay does not remove const
  return *paocc; // FAIL: missing diagnostic
}

char *str_from_static(void)
{
  // constraint violation: array to pointer decay does not remove const
  static const char s[10];
  return s;
}

2: Exact command used to run SDCC on this sample code

sdcc --stack-auto --std=c23 -c decay2.c

3: SDCC version tested (type "sdcc -v" to find it)

SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/f8/f8l TD- 4.5.24 #16456 (Mac OS X ppc)
published under GNU General Public License (GPL)

4: Copy of the error message or incorrect output, or a clear description of the observed versus expected behavior.

A constraint violation should be reported in all three functions, but it is only reported in the first:

decay2.c:8: warning 196: pointer target lost const qualifier

(I also noticed that replacing the const qualifiers with volatile prevents a constraint violation from being reported in any of the functions.)

Discussion


Log in to post a comment.

Auth0 Logo