Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-19 Thread Ondrej Pokorny
On 12.05.2019 16:36, Jonas Maebe wrote: Thanks. I have added these warnings to the compiler in r42047, and also the static/dynamic errors for Standard resp. Extended ISO Pascal. By default, the warnings are enabled for * enums * boolean * integer subrange types that don't span the entire range

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Martok
Hi, don't get me wrong, I like having something of mine included, but I'm genuinely surprised you used it in the way I designed it. As you said, the warning and code that is actually generated must agree, otherwise they're useless. And there is a huge gap in the definition of the Freepascal

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Jonas Maebe
On 12/05/2019 19:39, Ondrej Pokorny wrote: On 12.05.2019 18:56, Jonas Maebe wrote: As far as range checking and undefined behaviour is concerned, they do. I.e., you won't get undefined behaviour by assigning any value between low(enum)..high(enum) to them. Very good, thank you. IMO this

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Ondrej Pokorny
On 12.05.2019 18:56, Jonas Maebe wrote: As far as range checking and undefined behaviour is concerned, they do. I.e., you won't get undefined behaviour by assigning any value between low(enum)..high(enum) to them. Very good, thank you. IMO this should be clearly documented to avoid

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Jonas Maebe
On 12/05/2019 18:30, Ondrej Pokorny wrote: On 12.05.2019 17:45, Jonas Maebe wrote: It's because Pred and Succ do not make sense with enumerations with holes in our opinion, and could be confusing. E.g. in your example, one could expect at first sight that succ(one) = two. It depends if the

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Ondrej Pokorny
On 12.05.2019 17:45, Jonas Maebe wrote: On 12/05/2019 17:14, Ondrej Pokorny wrote: On 12.05.2019 16:36, Jonas Maebe wrote: Thanks. I have added these warnings to the compiler in r42047, and also the static/dynamic errors for Standard resp. Extended ISO Pascal. Very nice. One question about

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Jonas Maebe
On 12/05/2019 17:14, Ondrej Pokorny wrote: On 12.05.2019 16:36, Jonas Maebe wrote: Thanks. I have added these warnings to the compiler in r42047, and also the static/dynamic errors for Standard resp. Extended ISO Pascal. Very nice. One question about "C-style enumeration types"

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Ondrej Pokorny
On 12.05.2019 16:36, Jonas Maebe wrote: Thanks. I have added these warnings to the compiler in r42047, and also the static/dynamic errors for Standard resp. Extended ISO Pascal. Very nice. One question about "C-style enumeration types"

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-05-12 Thread Jonas Maebe
On 01/01/2019 22:10, Martok wrote: The attached patch adds two messages inspired by C compiler's -Wswitch-enum and -Wcovered-switch-default. Building on the recent label count refactoring, this was fairly straightforward. - If a case statement on an ordinal does not contain labels for all

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Michael Van Canneyt
On Wed, 2 Jan 2019, Martok wrote: Am 02.01.2019 um 17:56 schrieb Michael Van Canneyt: The compiler can prove that since the methods are private. It can see no explicit calls are generated for it. I thought so too, but even with added explicit calls, there is no warning. Plus, it could only

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Jonas Maebe
On 02/01/19 17:41, Martok wrote: Wait - why does that code not raise a 5033 "Function Result does not seem to be set"? Add a second property "Property MyOtherString : String Index 2 Read GetString;", and now its provably wrong. No warning. This seems wrong, considering what we just talked about

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Martok
Am 02.01.2019 um 11:30 schrieb Florian Klämpfl: > The compiler is for speed reasons not compiled with $R+/$O+, so the safety > else clause have its purpose, but they should > throw an internal error instead. And here we are at that other issue again. There is absolutely no guarantee the safety

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Michael Van Canneyt
On Wed, 2 Jan 2019, Martok wrote: Am 02.01.2019 um 11:19 schrieb Michael Van Canneyt: Consider the following: Type TMyClass = class Private function GetString(AIndex: Integer): string; Published Property MyString : String Index 1 Read GetString; end; function

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Ralf Quint
On 1/2/2019 2:18 AM, Sven Barth via fpc-devel wrote: Am Mi., 2. Jan. 2019, 09:44 hat Martok > geschrieben: * in ISO mode, there are 2 solutions: in Standard Pascal, not covering the entire type is a compile-time error. In Extended Pascal, this is a

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Benito van der Zander
Wait - why does that code not raise a 5033 "Function Result does not seem to be set"? Add a second property "Property MyOtherString : String Index 2 Read GetString;", and now its provably wrong. No warning. This seems wrong, considering what we just talked about on fpc-pascal. Because there

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Martok
Am 02.01.2019 um 11:19 schrieb Michael Van Canneyt: > Consider the following: > > Type >TMyClass = class >Private > function GetString(AIndex: Integer): string; >Published > Property MyString : String Index 1 Read GetString; >end; > > function

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Martok
Am 02.01.2019 um 11:06 schrieb Bart: > So now I will have to add a useless else statement for every case > statement that uses e.g. integers, Well, as Jonas argues on fpc-pascal, you are supposed to add useless statements anyway, which the compiler will then 100% remove... j/k. In all

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Michael Van Canneyt
On Wed, 2 Jan 2019, Mattias Gaertner via fpc-devel wrote: > Warnings can always be disabled by {$warn NR off} or - I believe - a > command line switch. > One could also decide to have it be a default off warning for the > non ISO modes (FPC, Delphi, MacPas) like some of the string >

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Mattias Gaertner via fpc-devel
On Wed, 2 Jan 2019 12:05:17 +0100 (CET) Michael Van Canneyt wrote: > On Wed, 2 Jan 2019, Sven Barth via fpc-devel wrote: > > > Am Mi., 2. Jan. 2019, 11:08 hat Bart > > geschrieben: > >> On Wed, Jan 2, 2019 at 9:44 AM Martok > >> wrote: > >>> - If a case statement on an ordinal does not

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Michael Van Canneyt
On Wed, 2 Jan 2019, Sven Barth via fpc-devel wrote: Am Mi., 2. Jan. 2019, 11:08 hat Bart geschrieben: On Wed, Jan 2, 2019 at 9:44 AM Martok wrote: - If a case statement on an ordinal does not contain labels for all values of the ordinal, and no else statement is given, raise a new

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Bart
On Wed, Jan 2, 2019 at 11:22 AM Florian Klämpfl wrote: > Which ordinal changes in FPC its range depending on the architecture? Integer is not the same range on 16-bit platform IIRC? -- Bart ___ fpc-devel maillist - fpc-devel@lists.freepascal.org

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Marco Borsari via fpc-devel
Il 01/01/2019 22:10, Martok ha scritto: - If a case statement on an ordinal does not contain labels for all values of the ordinal, and no else statement is given, raise a new warning (W6059). This is actually defined as an error in ISO7185 and a dynamic-violation in IEC10206. * in ISO mode,

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Florian Klämpfl
Am 01.01.2019 um 22:10 schrieb Martok: > > * Building the compiler itself cycles with -Sew, so it bails on the first > occurrence of one of these issues - turns out they're all over the place. > However... I think the warnings are correct and expose imperfect code here. > Take this example (one

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread LacaK
>> - If a case statement on an ordinal does not contain labels for all values of >> the ordinal, and no else statement is given, raise a new warning (W6059). >> This >> is actually defined as an error in ISO7185 and a dynamic-violation in >> IEC10206. > So now I will have to add a useless else

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Florian Klämpfl
Am 02.01.2019 um 11:06 schrieb Bart: > On Wed, Jan 2, 2019 at 9:44 AM Martok wrote: > >> - If a case statement on an ordinal does not contain labels for all values of >> the ordinal, and no else statement is given, raise a new warning (W6059). >> This >> is actually defined as an error in

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Sven Barth via fpc-devel
Am Mi., 2. Jan. 2019, 11:08 hat Bart geschrieben: > On Wed, Jan 2, 2019 at 9:44 AM Martok wrote: > > > - If a case statement on an ordinal does not contain labels for all > values of > > the ordinal, and no else statement is given, raise a new warning > (W6059). This > > is actually defined as

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Michael Van Canneyt
On Tue, 1 Jan 2019, Martok wrote: Hi all, The attached patch adds two messages inspired by C compiler's -Wswitch-enum and -Wcovered-switch-default. Building on the recent label count refactoring, this was fairly straightforward. - If a case statement on an ordinal does not contain labels

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Sven Barth via fpc-devel
Am Mi., 2. Jan. 2019, 09:44 hat Martok geschrieben: > * in ISO mode, there are 2 solutions: in Standard Pascal, not covering the > entire type is a compile-time error. In Extended Pascal, this is a runtime > error. Which one is followed usually? > ISO and Extended Pascal are handled as two

Re: [fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Bart
On Wed, Jan 2, 2019 at 9:44 AM Martok wrote: > - If a case statement on an ordinal does not contain labels for all values of > the ordinal, and no else statement is given, raise a new warning (W6059). This > is actually defined as an error in ISO7185 and a dynamic-violation in > IEC10206. So

[fpc-devel] [Patch/RFC] Warnings for (in/over)complete case statements

2019-01-02 Thread Martok
Hi all, The attached patch adds two messages inspired by C compiler's -Wswitch-enum and -Wcovered-switch-default. Building on the recent label count refactoring, this was fairly straightforward. - If a case statement on an ordinal does not contain labels for all values of the ordinal, and no