www.digitalmars.com         C & C++   DMDScript  

D.gnu - GDC doesn't catch this ambiguity

reply "Mike" <none none.com> writes:
In the following code:

module trace;

private nothrow pure void SendCommand(in int command, in void*
message)
{
      asm
      {
	"mov r0, %[cmd];
	mov r1, %[msg];

	:
	: [cmd] "r" command, [msg] "r" message
	: "r0", "r1";
      };
}

private static nothrow pure void SendMessage(in void* ptr, in
uint length)
{
      // Create semihosting message message
      uint[3] message =
      [
	2, 	          // stderr
	cast(uint)ptr,    // ptr to string
	length            // size of string
      ];

      // Send semihosting command
      SendCommand(0x05, &message);
}

struct Trace
{
      static nothrow pure void Write(in string text)
      {
	SendMessage(text.ptr, text.length);
      }

      static nothrow pure void Write(uint value)
      {
	char[32] buffer;
	
	char* p = buffer.ptr + 31;
	do
	{
	    p--;
	    *p = '0' + (value % 10);
	    value /= 10;
	} while(value > 0);

	SendMessage(p, (buffer.ptr + 31) - p);
      }

      static nothrow pure void Write(A...)(A a)
      {
	foreach(t; a)
	{
	    Write(t);
	}
      }

      static nothrow pure void WriteLine(A...)(A a)
      {
	foreach(t; a)
	{
	    Write(t);
	}
	Write("\r\n");
      }
}

GDC doesn't catch the ambiguity between...
    static nothrow pure void Write(A...)(A a)
      and
    static nothrow pure void Write(in string text)
... but LDC does.

Who's right?
Jan 10 2014
parent reply "Mike" <none none.com> writes:
On Saturday, 11 January 2014 at 00:45:20 UTC, Mike wrote:
 In the following code:

 module trace;

 private nothrow pure void SendCommand(in int command, in void*
 message)
 {
      asm
      {
 	"mov r0, %[cmd];
 	mov r1, %[msg];

 	:
 	: [cmd] "r" command, [msg] "r" message
 	: "r0", "r1";
      };
 }

 private static nothrow pure void SendMessage(in void* ptr, in
 uint length)
 {
      // Create semihosting message message
      uint[3] message =
      [
 	2, 	          // stderr
 	cast(uint)ptr,    // ptr to string
 	length            // size of string
      ];

      // Send semihosting command
      SendCommand(0x05, &message);
 }

 struct Trace
 {
      static nothrow pure void Write(in string text)
      {
 	SendMessage(text.ptr, text.length);
      }

      static nothrow pure void Write(uint value)
      {
 	char[32] buffer;
 	
 	char* p = buffer.ptr + 31;
 	do
 	{
 	    p--;
 	    *p = '0' + (value % 10);
 	    value /= 10;
 	} while(value > 0);

 	SendMessage(p, (buffer.ptr + 31) - p);
      }

      static nothrow pure void Write(A...)(A a)
      {
 	foreach(t; a)
 	{
 	    Write(t);
 	}
      }

      static nothrow pure void WriteLine(A...)(A a)
      {
 	foreach(t; a)
 	{
 	    Write(t);
 	}
 	Write("\r\n");
      }
 }

 GDC doesn't catch the ambiguity between...
    static nothrow pure void Write(A...)(A a)
      and
    static nothrow pure void Write(in string text)
 ... but LDC does.

 Who's right?
LDC the LLVM D compiler (0.12.1): based on DMD v2.063.2 and LLVM 3.3 GDC arm-none-eabi-gdc (GCC) 4.8.2 Copyright (C) 2013 Free Software Foundation, Inc. Also, is there a way to know which version of DMD GDC is based on?
Jan 10 2014
parent reply Iain Buclaw <ibuclaw gdcproject.org> writes:
On 11 January 2014 01:13, Mike <none none.com> wrote:
 LDC
 the LLVM D compiler (0.12.1):
   based on DMD v2.063.2 and LLVM 3.3

 GDC
 arm-none-eabi-gdc (GCC) 4.8.2
 Copyright (C) 2013 Free Software Foundation, Inc.

 Also, is there a way to know which version of DMD GDC is based on?
GDC is on 2.064.2, which uses a newer frontend than LDC.
Jan 11 2014
next sibling parent "sclytrack" <sclytrack birthday.com> writes:
On Saturday, 11 January 2014 at 12:39:59 UTC, Iain Buclaw wrote:
 On 11 January 2014 01:13, Mike <none none.com> wrote:
 LDC
 the LLVM D compiler (0.12.1):
   based on DMD v2.063.2 and LLVM 3.3

 GDC
 arm-none-eabi-gdc (GCC) 4.8.2
 Copyright (C) 2013 Free Software Foundation, Inc.

 Also, is there a way to know which version of DMD GDC is based 
 on?
GDC is on 2.064.2, which uses a newer frontend than LDC.
:~$ gdc --version gdc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. That probably was a feature request on the output of gdc --version to list "based on DMD 2.064.2"
Jan 11 2014
prev sibling parent reply "Mike" <none none.com> writes:
On Saturday, 11 January 2014 at 12:39:59 UTC, Iain Buclaw wrote:
 On 11 January 2014 01:13, Mike <none none.com> wrote:
 GDC doesn't catch the ambiguity between...
    static nothrow pure void Write(A...)(A a)
      and
    static nothrow pure void Write(in string text)
 ... but LDC does.

 Who's right?
 GDC is on 2.064.2, which uses a newer frontend than LDC.
So is difference in frontends the reason for the difference between the two compilers in this case?
Jan 11 2014
parent "Mike" <none none.com> writes:
On Saturday, 11 January 2014 at 23:12:52 UTC, Mike wrote:
 On Saturday, 11 January 2014 at 12:39:59 UTC, Iain Buclaw wrote:
 On 11 January 2014 01:13, Mike <none none.com> wrote:
 GDC doesn't catch the ambiguity between...
   static nothrow pure void Write(A...)(A a)
     and
   static nothrow pure void Write(in string text)
 ... but LDC does.

 Who's right?
 GDC is on 2.064.2, which uses a newer frontend than LDC.
So is difference in frontends the reason for the difference between the two compilers in this case?
I'm guess this changed explains the difference. http://dlang.org/changelog.html#template_overload_set
Jan 11 2014