Menu ▾ ▴

#4130 Inappropriate warning when using typeof(nullptr)

open
nobody
None
Front-end
5
14 hours ago
1 day ago
No

1: Sample code that reproduces the problem.

typeof(nullptr) test (int condition)
{
  return condition ? nullptr : nullptr;
}

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

sdcc --std=c23 bug.c

3: SDCC version tested

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/huc6280/f8/f8l TD- 4.6.4 #16997 (Linux)

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

<source>:2: warning 361: qualifier on return type has no effect

GCC 16.2 produces no diagnostic message for the same translation unit: https://godbolt.org/z/9c73hGPKn

Related

Bugs: #4136

Discussion

  • Christopher Bazley

    Christopher Bazley - 19 hours ago

    This bug is tangentially related to [bugs:#4136].

     

    Related

    Bugs: #4136


    Last edit: Christopher Bazley 19 hours ago
  • Christopher Bazley

    Christopher Bazley - 14 hours ago

    Please consider the attached candidate fix patch.

    Scalar literals carry an internal const flag. typeof copied it into C object and return types, causing a spurious warning for typeof(nullptr) and rejecting assignments to literal-derived objects. Remove the flag when copying a scalar literal type, while preserving genuine object qualification even when a constexpr object's value is folded.

    Testing: 77 valdiag checks and 5 Z80 runtime assertions passed. Diagnostic configurations tested: Z80, STM8, MCS51, MCS51 large, MCS51 stack-auto, PDK14, S08. All focused checks passed. The counts include positive cases as well as expected diagnostics.

     

Log in to post a comment.