[Issue 10482] Regression (2.063): Compiler allows constant global functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 30 09:56:40 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10482



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-30 09:56:33 PDT ---
(In reply to comment #3)
> IMHO this is invalid / won't fix.

See my comments:
http://d.puremagic.com/issues/show_bug.cgi?id=10150#c4
http://d.puremagic.com/issues/show_bug.cgi?id=10150#c5

I'm reposting them here:

(In reply to comment #4)
> I disagree with this change, this is extremely dangerous behavior when
> interfacing with C. Take a look at the following:
> 
> -----
> extern(C) const int *foo();
> 
> void main()
> {
>     *foo() = 1;  // compiles
> }
> -----
> 
> The proper definition should have been:
> 
> -----
> extern(C) const(int)* foo();
> 
> void main()
> {
>     *foo() = 1;  // fails
> }
> -----
> 
> It is very easy to make this mistake, it should not be silent, at least not for
> module-scoped functions.
> 
> Alternatively as a compromise I suggest we at least add this check for
> extern(C) functions, because this is where this problem can occur very
> frequently.


(In reply to comment #4)
> I disagree with this change, this is extremely dangerous behavior when
> interfacing with C. Take a look at the following:
> 
> -----
> extern(C) const int *foo();
> 
> void main()
> {
>     *foo() = 1;  // compiles
> }
> -----
> 
> The proper definition should have been:
> 
> -----
> extern(C) const(int)* foo();
> 
> void main()
> {
>     *foo() = 1;  // fails
> }
> -----
> 
> It is very easy to make this mistake, it should not be silent, at least not for
> module-scoped functions.
> 
> Alternatively as a compromise I suggest we at least add this check for
> extern(C) functions, because this is where this problem can occur very
> frequently.

(In reply to comment #5)
> Another alternative is to make the compiler smarter, and only disallow const
> where it's only applied to one function, for example:
> 
> -----
> const int * foo();  // disallowed
> 
> const
> {
>     int * foo();  // ok
>     int * bar();  // ok
> }
> 
> const:
> int * foo();  // ok
> -----
> 
> This would be for the sake of convenience, to avoid breaking existing code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list