www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1603] New: Overload sets bug

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

           Summary: Overload sets bug
           Product: D
           Version: 2.007
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: andrei metalanguage.com


The following code does not compile:

module A;
extern(C) void foo(in char*) {}
// end of module

module B;
void foo(string) {}
// end of module

import A, B;

main()
{
  foo("string");
}

The call is ambiguous although it should make it to B.foo.


-- 
Oct 20 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1603


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from smjg iname.com  2007-10-21 08:09 -------
If it's ambiguous, it should error.  This kind of hijacking is exactly why
overload sets are defined the way they are.


-- 
Oct 21 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1603


andrei metalanguage.com changed:

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




------- Comment #2 from andrei metalanguage.com  2007-10-21 11:20 -------
Literal strings should not bind to const char *. The overload sets
corresponding to the two functions are disjoint.


-- 
Oct 21 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1603


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |spec
            Summary|Overload sets bug           |String literals bind to
                   |                            |pointer types




------- Comment #3 from smjg iname.com  2007-10-21 12:28 -------
(In reply to comment #2)
 Literal strings should not bind to const char *.
By my experiments, string literals are simultaneously of all of these types: invariant(char)* invariant(wchar)* invariant(dchar)* invariant(char)[] invariant(wchar)[] invariant(dchar)[] and therefore to the const versions of these types. But there doesn't seem to be any documentation to the fact that they bind to the pointer types (unless I haven't found it). So the issue has nothing to do with overload sets. Try this and see. ---------- extern(C) void foo(in char*) {} void main() { foo("string"); } invariant(char)* cp = "string"; invariant(wchar)* wp = "string"; invariant(dchar)* dp = "string"; invariant(char)[] ca = "string"; invariant(wchar)[] wa = "string"; invariant(dchar)[] da = "string"; ---------- And why is this issue set to version 2.007? That version isn't even out yet. --
Oct 21 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1603


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.007                       |unspecified




------- Comment #4 from andrei metalanguage.com  2007-10-21 12:33 -------
(In reply to comment #3)
 (In reply to comment #2)
 Literal strings should not bind to const char *.
By my experiments, string literals are simultaneously of all of these types: invariant(char)* invariant(wchar)* invariant(dchar)* invariant(char)[] invariant(wchar)[] invariant(dchar)[] and therefore to the const versions of these types. But there doesn't seem to be any documentation to the fact that they bind to the pointer types (unless I haven't found it). So the issue has nothing to do with overload sets.
You are right. I suggest we leave this bug opened with the new title until a formal resolution is found. Although accepting conversion of string literals to invariant char* is sound, in my opinion that's a bit too friendly towards C functions, and it creates unnecessary ambiguity. It's not too hard to add a .ptr when calling a C function. (I've set the version to unspecified.) --
Oct 21 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1603


bugzilla digitalmars.com changed:

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




------- Comment #5 from bugzilla digitalmars.com  2009-03-11 14:56 -------
Fixed dmd 2.026


-- 
Mar 11 2009