News for hackers. Stuff that matters.
Re:C++ Papercuts by shortrounddev2 on Monday August 28, 2023 @09:00AM (#37293271)
Microsoft created SAL so you can annotate pointers to instruct the compiler to put up warnings or even errors for null required fields:

    _Success_(return)  //out parameters should be set if this returns true
    bool tryGetValue(
      _In_ Map const* map, //pointer is for input only and cannot be null
      _In_ char const* name,
      _Out_opt_ Data* value //pointer is for output and can be null
    );
If you pass null for _In_ params, the compiler will warn or error. You return true without setting the _out_opt_ parameters, the compiler will warn or error. You can pass null to _out_opt_, and the compiler will warn or error if the function body doesn't properly check if the parameter is null
Re:C++ Papercuts by fluoridation on Monday August 28, 2023 @10:20AM (#37294428)
Of course, that only works if you're passing a literal null. If you're passing a variable the compiler will not check anything, so this doesn't really solve the problem.
Re:C++ Papercuts by jprete on Monday August 28, 2023 @10:26AM (#37294542)
The annotation does need to be propagated backwards to callers and declarers - and there needs to be a way to "annotate" an existing pointer in the scopes where you've proven that it's not null - but that's better than having no annotation at all.

(Although this is something I'd 100% want C++ to do, and not with an annotation but with a very short operator or reserved word.)