www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10482] New: Regression (2.063): Compiler allows constant global functions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482

           Summary: Regression (2.063): Compiler allows constant global
                    functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-06-26
17:42:58 PDT ---
-----
const int * foo();

void main() { }
-----

2.062:
$ dmd test.d
 test.d(3): Error: function test.foo without 'this' cannot be const/immutable
2.063: $ dmd test.d
 
I'm not sure how this happened, I remember we had a test-suite covering these. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 26 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482


Henning Pohl <henning still-hidden.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |henning still-hidden.de


--- Comment #1 from Henning Pohl <henning still-hidden.de> 2013-06-27 10:19:26
PDT ---
This behaviour is wanted, moving const after the function name will produce an
error:

int* foo() const;

----
Error: function main.foo without 'this' cannot be const
----

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 27 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2013-06-30 08:58:27 PDT ---
See also Issue 10511

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482


Dicebot <m.strashun gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m.strashun gmail.com


--- Comment #3 from Dicebot <m.strashun gmail.com> 2013-06-30 09:39:08 PDT ---
This is irrelevant to Issue 10511. Global const functions are still invalid, no
regressions here : http://dpaste.1azy.net/a2500829

Looks like 2.062 had bug in parser and coupled leading 'const' with function
type instead of return type. IMHO this is invalid / won't fix.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich 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: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-06-30
09:57:38 PDT ---
Sorry for the duplicate paste of comment 4.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482



--- Comment #6 from Dicebot <m.strashun gmail.com> 2013-06-30 10:31:52 PDT ---
Yeah, have figure out that it is actually no-op in prefix mode now. Still not
what title claims, but is.. inconvenient. Moving in that thread.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|regression                  |enhancement


--- Comment #7 from Kenji Hara <k.hara.pg gmail.com> 2013-07-02 07:25:01 PDT ---
This is an intended change comes from issue 10150, so is not a regression.

Today dmd never distinguishes prefix storage class and scopes/labeled ones.
That's a design decision which sometimes talked by Walter.

But also, I can agree that it is a little bug-prone behavior.
So I switch this into enhancement issue.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10482



--- Comment #8 from Dicebot <m.strashun gmail.com> 2013-07-02 08:43:42 PDT ---
(In reply to comment #7)
 This is an intended change comes from issue 10150, so is not a regression.
 
 Today dmd never distinguishes prefix storage class and scopes/labeled ones.
 That's a design decision which sometimes talked by Walter.
 
 But also, I can agree that it is a little bug-prone behavior.
 So I switch this into enhancement issue.
Yep, it is not a regression but a breaking change introduces by 10150, which should not have been implemented in the first place. I wish I have noticed that pull request before it was merged. There is currently minor discussion on topic in 10150 thread. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2013