www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4976] New: Can't use auto on const member functions.

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

           Summary: Can't use auto on const member functions.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: peter.alexander.au gmail.com



17:26:27 PDT ---
When you try to use type inference on a const member function, you get a
compiler error:

class Foo
{
public:
    auto foo() const { return 0; }    
}

Compiling gives:

test.d(4): no identifier for declarator foo
test.d(4): semicolon expected, not 'const'
test.d(4): Declaration expected, not 'return'

Removing the 'const' allows it to compile, but the function can no longer be
called on const objects.

The same applies for structs and  property methods.

This is using DMD 2.049.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 02 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4976


Simen Kjaeraas <simen.kjaras gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras gmail.com
         Resolution|                            |INVALID



PDT ---
This is because const and auto are both storage classes. What you want is
easily achieved by using this syntax:

class Foo {
    public:
       const foo( ) {
           return 0;
       } 
}

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




17:51:12 PDT ---
Oh, I would have never expected that.

Thanks.

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


Stewart Gordon <smjg iname.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
             Status|RESOLVED                    |REOPENED
                 CC|                            |smjg iname.com
         Resolution|INVALID                     |
           Severity|major                       |enhancement



But given its counter-intuitiveness, surely this is just a quirk of the
grammar, and not a deliberate design feature?

I suppose this is really part of the quirk whereby the grammar handles auto as
an attribute rather than as what it should be: a placeholder for a type.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED



Fixed in 2.054.

https://github.com/D-Programming-Language/dmd/commit/6a15077f8189e1ef203565edaebc766446aa105b

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