www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8634] New: Anonymous function parameters

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

           Summary: Anonymous function parameters
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: maxim maxim-fomin.ru



---
void foo(int)
{

}

void main()
{
    foo(5);
}

Although anonymous function parameters may be used in function declarations, it
seems that dmd doesn't check whether a function declaration is a definition
too.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8634


bearophile_hugs eml.cc changed:

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




 void foo(int)
 {
 
 }
 
 void main()
 {
     foo(5);
 }
 
 Although anonymous function parameters may be used in function declarations, it
 seems that dmd doesn't check whether a function declaration is a definition
 too.
What's the problem here? foo() not giving a name to its first argument means the programmer is stating foo() never uses its first argument, and the D language allows the programmer to enforce this desire. This feature also allows to avoid "unused argument warnings" once/where such warning is available. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8634




---


 void foo(int)
 {
 
 }
 
 void main()
 {
     foo(5);
 }
 
 Although anonymous function parameters may be used in function declarations, it
 seems that dmd doesn't check whether a function declaration is a definition
 too.
What's the problem here? foo() not giving a name to its first argument means the programmer is stating foo() never uses its first argument, and the D language allows the programmer to enforce this desire. This feature also allows to avoid "unused argument warnings" once/where such warning is available.
The problem is that such code is likely to be a bug (parameter name was forgotten) and compiler should report about this. BTW dmd doesn't produce any warning for unused variable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
parent reply "Namespace" <rswhite4 googlemail.com> writes:
 BTW dmd doesn't produce any warning for unused variable.
And this will never change. ;)
Sep 09 2012
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
On Sunday, 9 September 2012 at 19:59:02 UTC, Namespace wrote:
 BTW dmd doesn't produce any warning for unused variable.
And this will never change. ;)
Who knows, maybe eventually I'll be able to convince GDC maintainers to introduce this warning :-)
Sep 09 2012
parent "Namespace" <rswhite4 googlemail.com> writes:
On Sunday, 9 September 2012 at 20:19:51 UTC, bearophile wrote:
 On Sunday, 9 September 2012 at 19:59:02 UTC, Namespace wrote:
 BTW dmd doesn't produce any warning for unused variable.
And this will never change. ;)
Who knows, maybe eventually I'll be able to convince GDC maintainers to introduce this warning :-)
But he said dmd. :P
Sep 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8634






 The problem is that such code is likely to be a bug (parameter name was
 forgotten) and compiler should report about this.
I care a lot about removing bug-prone situations from D language. And I think avoiding bug-prone features. But in general it's not so common to forget to add a name for the argument. And even in the cases where I have forgotten to put the argument name, this is usually not a big problem, because the compiler doesn't find the name you are using inside the function, and gives you a nice compilation error at the first usage attempt, close enough to the function signature (unless your functions are really long). In theory one bug-prone situation is when you use a name thinking it's the name of a local argument, while you have not given a name to the argument, and you have a name in an outer scope that is the same. So you are actually using the name of the outer scope. In practice my diary of bugs shows I have never hit this bug, also because it's generally a good practice to not define local names equal to outer names. So unless you have evidence that this is a common enough bug (even few anecdotes are enough to keep this discussion open) I think this bug report should be closed.
 BTW dmd doesn't produce any warning for unused variable.
I know, but probably someday some D compiler will report them. It's an useful feature and it's not too much hard to implement. All the major C++ compilers have an option to report them. But note here I was not referring to a generic "unused variable" warning, I was referring to more specifically to a "unused argument" warning. If you omit the argument name, the warning is silenced. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8634


Maxim Fomin <maxim maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



---
I have no desire for disputes about things which are not necessarily defective
(as revealed here) and claimed by D people to be intentional part of the
language.

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