Lazarus

Free Pascal => FPC development => Topic started by: 440bx on April 04, 2019, 03:31:02 pm

Title: Mismatch in header notification definitions causes not-applicable warnings
Post by: 440bx on April 04, 2019, 03:31:02 pm
Hello,

The Header control notifications are defined as being negative constants but, the NMHDR.code they are compared against is defined as a longword.

This causes warnings from FPC. Specifically:

Warning: range check error while evaluating constants (-306 must be between 0 and 4294967295)

This occurs for all the notification codes used by the header control.

Title: Re: Mismatch in header notification definitions causes not-applicable warnings
Post by: PascalDragon on April 05, 2019, 09:14:37 am
Would you mind providing a bit more context, please? Cause right now it isn't really clear what exactly you're talking about.
Title: Re: Mismatch in header notification definitions causes not-applicable warnings
Post by: Thaddy on April 05, 2019, 09:55:52 am
NMHDR record member constants itself are declared as signed integers (probably legacy) but the winapi NMHDR expects  longword members. Hence the compiler barks.
(/win/wininc/struct.inc is correct, messages.inc isn't)

To suppress, cast to longword on use as a work-around.
Solution is possibly to redeclare
Code: Pascal  [Select]
  1. const
  2.   HDM_TESTDUMMY = longword(-321); // instead of HDM_TESTDUMMY = -(321)
  3. var i:longint;
  4.     j:longword;  
  5. begin
  6.     i:=HDM_TESTDUMMY;  // testlongword.pas(6,8) Warning: Range check error while evaluating constants (4294966975 must be between -2147483648 and 2147483647)
  7.     j:=HDM_TESTDUMMY;  // OK.
  8.     writeln(i,'|',j);
  9. end.
Is that enough context?
[edit]
reported in Mantis as #0035324

p.s. the example actually reverses the issue to make it clear.
Title: Re: Mismatch in header notification definitions causes not-applicable warnings
Post by: ASerge on April 05, 2019, 08:13:28 pm
For clarification.
SDK defines such const as unsigned (commctrl.h):
Code: C  [Select]
  1. #define HDN_FIRST               (0U-300U)       // header
But FPC as signed (commctrl.pp)
Code: Pascal  [Select]
  1. HDN_FIRST                      = (0-300);          // header
So it will be enough to specify
Code: Pascal  [Select]
  1. HDN_FIRST                      = LongWord(0-300);          // header
Title: Re: Mismatch in header notification definitions causes not-applicable warnings
Post by: 440bx on April 05, 2019, 08:34:58 pm
Code: Pascal  [Select]
  1. HDN_FIRST                      = (0-300);          // header
So it will be enough to specify
Code: Pascal  [Select]
  1. HDN_FIRST                      = LongWord(0-300);          // header
Yes, fortunately, it is a very simple thing to fix.
Title: Re: Mismatch in header notification definitions causes not-applicable warnings
Post by: Thaddy on April 05, 2019, 09:30:17 pm
Yes. As I showed before ASerge. Aside: it is indeed legacy..