i can't grasp myself how this is different to -Wnull-dereference
known with gcc (not implying such diagnostics should be or could be implemented
with tcc nor that it was any better or worse than _Optional added)
Hence please don't take offense when a non-expert such as myself is asking.

and i can't fully grasp how _Optional helps with a pointer must be tested
for if(ptr != NULL) _before_ dereferencing, in any case, with or without
_Optional. Not sure of the semantics either. A pointer in C can be NULL
and it must be tested for.

In Java i had seen some syntatic sugar with Optional<> implementation
for null-testing with instance1?.instance2.?instance3 etc... which actually
could improve readability of source code a bit.
But i cannot yet envision an equivalent for C-lang and if at all this was
desirable and how mentioned Java-specific implementation relates to C, if at all
Maybe i missed something.
I am not sure either, if compile-time diagnostics must be implemented as
language feature, if those could be implemented as compiler-feature
(-Wnull-dereference, don't know if that's reliable). Referring to
-Wwrite-strings seems not plausible, since to my knowledge this did not
introduce a new language feature equivalent to _Optional.
I would propose compile-time diagnostics should be distinguished from
language-features added, in particular when a diagnostic can be implemented
without adding language-features. For example MISRA C defines a set of criteria
compiler diagnostics (static code analysis) can test for _without_ adding
language features. Adding language features aren't desirable or necessary
always. It's up to ISO/IEC to decide.

Did _Optional proposal already surpass "draft" status?
In any case tcc won't error when hitting _Optional qualifier,
if that was accepted by ISO/IEC for C-lang as-is.

C-lang by design is not Java nor rust to follow along. And C-lang was
relatively stable for decades. Would be curious of a second opinion on this.
If _Optional qualifier does not break anything and does not obfuscate the
source-code of tcc, it's a none issue then.

On 2026-11-20 21:12, Christopher Bazley wrote:
> Dear TCC developers,
> 
> I pushed 205f264b9e01 to mob earlier. It adds -Wnull-to-nonoptional,
> which warns when a null pointer constant is implicitly converted to a
> pointer whose target type lacks the _Optional qualifier. The warning
> is off by default because such conversions are commonplace; however,
> in a program that uses _Optional, it is invaluable (equivalent to
> -Wwrite-strings for conversions to a pointer whose target type lacks
> the const qualifier).
> 
> Annex B of ISO/IEC DTS 26716 (WG14 N3951) lists this conversion as one
> for which an implementation can usefully warn. For example, with the
> warning enabled, "int *p = 0" is diagnosed and "_Optional int *p = 0"
> is not.
> 
> The compiler changes are small: 1 line added in libtcc.c, 2 in tcc.h,
> and 25 added and 2 removed in tccgen.c. Most of the work beyond the
> check in verify_assign_cast() is there to get cases like this right:
> 
> _Optional int *f(int ready, int *p)
> {
>     return ready ? p : 0;
> }
> 
> Warning as soon as TCC sees the null pointer constant would be
> premature because the return type is pointer-to-optional; if the
> return type were "int *" then the same expression should trigger a
> warning. TCC therefore remembers the null pointer conversion (nulls =
> 1) until it knows the destination type. Constant folding must preserve
> the distinction between (void *)0, which is a null pointer constant
> (nulls = 0), and (void *)(int *)0, which is not (nulls = -1).
> 
> If TCC has already cleared a local aggregate, it skips the store for
> an explicit initialiser such as .p = 0, so the patch checks the
> pointer conversion beforehand (by calling verify_assign_cast).
> 
> The tests add 95 lines and the documentation adds 8.
> 
> Thanks,
> Christopher
> 
> _______________________________________________
> Tinycc-devel mailing list
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel

-- 

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to