[Issue 19065] Struct invariant violated in @safe with T.init

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19065

Ali Ak  changed:

   What|Removed |Added

 CC||ali.akhtarz...@gmail.com

--- Comment #4 from Ali Ak  ---
(In reply to Walter Bright from comment #1)
> I think this change defeats the purpose of having an invariant. T.init is
> supposed to be a valid object, and so should pass the invariant.
> 
> It's not a bug, it's the way the language is designed to work.
> 
> To make this modification to the semantics, a fairly compelling use case
> will be required.

Does this mean the compile time constructed value of T must be a valid runtime
constructed value of T to be able to use invariants?

--


[Issue 18955] extern(C++) default struct mangling is overridden when interacting with a `cppmangle = class` tamplate

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18955

--- Comment #3 from Manu  ---
I'm sorry. I think I must have cut fail-ed. Remove the `Alloc` arg:
---
extern (C++, std)
{
struct char_traits(Char)
{
}
extern (C++, class) struct basic_string(T, Traits)
{
}
alias test_string = basic_string!(char, char_traits!char);
}
extern (C++) void test(ref const(std.test_string) str) {}
pragma(msg, test.mangleof);
---

Compile that, it will emit:
  ?test@@YAXAEBV?$basic_string@DV?$char_traits@D@std@@@std@@@Z
But it should emit:
  ?test@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@@std@@@Z

Notice the 'V?$char_traits' (class) should be a 'U?$char_traits' (struct);
char_traits is a struct.

If you add:
extern (C++, struct) struct char_traits(Char)

ie, tell it explicitly to mangle the struct as a struct, it mangles correctly.
Of course, a struct should mangle as a struct naturally though.

--


[Issue 19081] Can't declare enum with UDA at statement level

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19081

--- Comment #2 from Yuxuan Shui  ---
This is because, at statement level, enum is also a storage class:

enum X = 10;

I wonder why declaring enum without a UDA works at statement level. I smell
terrible hacks.

--


[Issue 19081] Can't declare enum with UDA at statement level

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19081

Yuxuan Shui  changed:

   What|Removed |Added

Summary|Can't declare enum with UDA |Can't declare enum with UDA
   |in unittest blocks  |at statement level

--- Comment #1 from Yuxuan Shui  ---
This is because, in

--


[Issue 19070] Invalid octal literals `01` through `07` allowed

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19070

--- Comment #1 from Hiroki Noda  ---
Attemptive PR : https://github.com/dlang/dmd/pull/8490

--


[Issue 19081] New: Can't declare enum with UDA in unittest blocks

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19081

  Issue ID: 19081
   Summary: Can't declare enum with UDA in unittest blocks
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: yshu...@gmail.com

Example:

@(1) enum A { A } // Fine
struct T1 {
@(1) struct T2 {} // Fine
@(1) enum A { A } // Fine
}
debug {
@(1) enum Op { Add, Sub } // Fine
}
unittest {
@(1) struct X { } // Fine
@(1) enum Op { Add, Sub } // Not fine ?!
}
void main() {}

https://godbolt.org/g/TSQeYW

--


[Issue 3567] std.traits: Unqual strips qualifiers on structs with references that would break const/immutable.

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #9 from Steven Schveighoffer  ---
I think a trait "ForceUnqual" may be needed in some cases, but "Unqual" I have
always expected to behave the way it does (except in the case of structs
containing references, for which it should not strip anything).

Man, it would be nice to have a tail-modifier in D...

--


[Issue 3567] std.traits: Unqual strips qualifiers on structs with references that would break const/immutable.

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #8 from Timoses  ---
(In reply to Steven Schveighoffer from comment #6)
> Note, the bug here in FeepingCreature's case is that it strips more than it
> should. It is supposed to be safe to use Unqual.
> 
> So the expectation that Unqual should remove all mutability modifiers is
> incorrect.

Tried to find examples where a complete stripping of qualifiers would break
something. I guess here it is really required that it only strips the "head"
qualifier:

https://github.com/dlang/phobos/blob/90a8fc387f25f9bdfc2c6ad4508da63c523be670/std/array.d#L1465

Though this is not the subject of this issue.. Should I perhaps create a new
issue for https://issues.dlang.org/show_bug.cgi?id=3567#c5 ? Perhaps asking for
a new trait?

--


[Issue 3567] std.traits: Unqual strips qualifiers on structs with references that would break const/immutable.

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3567

--- Comment #7 from Timoses  ---
(In reply to Steven Schveighoffer from comment #6)
> I'm changing the title accordingly. Perhaps we should actually close this
> bug and open another, as the whole issue has really been flipped around?

Perhaps you're looking for this? https://issues.dlang.org/show_bug.cgi?id=8338

--


[Issue 19059] Invalid integer literal 08 and 09 allowed

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19059

--- Comment #8 from github-bugzi...@puremagic.com ---
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/90ab1b325f26d08bd770cd9fd44bed085c775ad9
Fix Issue 19059 - Disallow `08` and `09` in integer literal

https://github.com/dlang/dmd/commit/cdedafdd22b6eb2dd5eb550d913c851d11dd28dc
Merge pull request #8451 from kubo39/disallow-invalid-octal-digital

Fix Issue 19059 - Disallow `08` and `09` in integer literal
merged-on-behalf-of: Steven Schveighoffer 

--


[Issue 3567] std.traits: Unqual strips qualifiers on structs with references that would break const/immutable.

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3567

Steven Schveighoffer  changed:

   What|Removed |Added

Summary|std.traits: Unqual doesn't  |std.traits: Unqual strips
   |handle arrays well  |qualifiers on structs with
   ||references that would break
   ||const/immutable.

--- Comment #6 from Steven Schveighoffer  ---
Note, the bug here in FeepingCreature's case is that it strips more than it
should. It is supposed to be safe to use Unqual.

So the expectation that Unqual should remove all mutability modifiers is
incorrect.

I'm changing the title accordingly. Perhaps we should actually close this bug
and open another, as the whole issue has really been flipped around?

--


[Issue 18979] Template constructor bypasses private

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18979

RazvanN  changed:

   What|Removed |Added

 CC||razvan.nitu1...@gmail.com

--- Comment #1 from RazvanN  ---
PR : https://github.com/dlang/dmd/pull/8488

--


[Issue 18955] extern(C++) default struct mangling is overridden when interacting with a `cppmangle = class` tamplate

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18955

Mike Franklin  changed:

   What|Removed |Added

 CC||slavo5...@yahoo.com

--- Comment #2 from Mike Franklin  ---
`alias string = basic_string!(char, char_traits!char);` has two template
arguments, but `extern (C++, class) struct basic_string(T, Traits, Alloc)` had
3.

This results in:
Error: template instance `basic_string!(char, char_traits!char)` does not match
template declaration

I'm not sure what I should be doing to reproduce the problem.

--


[Issue 19080] Order of overloads affects the chosen method

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19080

--- Comment #1 from RazvanN  ---
(In reply to RazvanN from comment #0)
> //a.d
> struct Foo
> {
> private void fun(A)(A a) {}
> void fun(int a) {}
> }
> 
> struct Bar
> {
> void fun(int a) {}
> private void fun(A)(A a) {}
> }
> 
> // b.d
I forgot add here: import a.d
> void main()
> {
> Foo a;
> a.fun(42);  // deprecation: a.Foo.fun is no visible
> Bar b;
> b.fun(42);  // ok
> }
> 
> Expectation : no deprecation at all

--


[Issue 19080] New: Order of overloads affects the chosen method

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19080

  Issue ID: 19080
   Summary: Order of overloads affects the chosen method
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: razvan.nitu1...@gmail.com

//a.d
struct Foo
{
private void fun(A)(A a) {}
void fun(int a) {}
}

struct Bar
{
void fun(int a) {}
private void fun(A)(A a) {}
}

// b.d
void main()
{
Foo a;
a.fun(42);  // deprecation: a.Foo.fun is no visible
Bar b;
b.fun(42);  // ok
}

Expectation : no deprecation at all

--


[Issue 8338] Unqual's documentation doesn't reflect its behavior on types with indirections

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=8338

Timoses  changed:

   What|Removed |Added

 CC||timos...@gmail.com

--- Comment #7 from Timoses  ---
(In reply to Peter Alexander from comment #5)
> Are there actually any use cases for stripping all qualifiers? If there are
> no use cases then there is no point adding it. I can't think of any.

Please see in issue 3567 for an example use case where a full Unqual is
required:
https://issues.dlang.org/show_bug.cgi?id=3567#c5

--


[Issue 3567] std.traits: Unqual doesn't handle arrays well

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3567

Timoses  changed:

   What|Removed |Added

 CC||timos...@gmail.com

--- Comment #5 from Timoses  ---
The fact the Unqual only "shallowly" unqualifies a type can be pretty annoying
when dealing with templates and inout functions.


struct S
{
int[] vals;   
}

template Temp(T)
{
class Temp
{
T t;

this(T t)
{ this.t = t; }

auto get() inout
{
static if (is(T == S))
{
import std.traits : Unqual;
alias tType = Unqual!(typeof(t.vals));
pragma(msg, tType); // inout(int)[]
return new inout Temp!tType(t.vals); // ERROR: Can't create
class Temp!(inout(int)[])
}
}
}
}

unittest
{
auto t = Temp!S;
t.get();
}

Error: variable `onlineapp.Temp!(inout(int)[]).Temp.t` only parameters or stack
based variables can be inout
Error: template instance `onlineapp.Temp!(inout(int)[])` error instantiating


In this case a complete stripping of qualifiers is required!

Related discussion:
https://forum.dlang.org/post/enwkjtdqivjldqpzz...@forum.dlang.org

--


[Issue 19079] New: Destructors not called in named unions

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19079

  Issue ID: 19079
   Summary: Destructors not called in named unions
   Product: D
   Version: D2
  Hardware: x86
OS: Windows
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: simen.kja...@gmail.com

When a type T with a destructor is placed in a named union, T's destructor is
not called when the union goes out of scope or is destroyed with destroy().

https://dlang.org/spec/struct.html states that 'Unions may not have fields that
have destructors', so this may be undefined behavior.


struct S  { ~this() { throw new Exception(""); } }
struct S1 { union { S s; } }
 union U  { S s; }
struct S2 { U u; }

unittest {
import std.exception;


// Correct behavior:
assertThrown((){ S s; }());
assertThrown((){ S s; destroy(s); }());
assertThrown((){ S1 s1; }());
assertThrown((){ S1 s1; destroy(s1); }());

// Incorrect behavior:
assertNotThrown((){ U u; }());
assertNotThrown((){ U u; destroy(u); }());
assertNotThrown((){ S2 s2; }());
assertNotThrown((){ S2 s2; destroy(s2); }());
}

--


[Issue 19076] dmd 2.081 crashed by getVirtualFunctions for a interface extended interface

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19076

--- Comment #8 from RazvanN  ---
(In reply to kntroh from comment #7)
> (In reply to Basile B. from comment #5)
> > sorry kntroh, i've been misleaded it was so similar.
> It's nothing :).
> Thanks for the quick fix!

Don't mention it!

--


[Issue 19078] New: dmd does not remove inlined functions

2018-07-12 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=19078

  Issue ID: 19078
   Summary: dmd does not remove inlined functions
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: enhancement
  Priority: P2
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: johnnymar...@gmail.com

I've attempted to create a minimal example to demonstrate that dmd fails to
remove inlined functions from the final executable.  In order to keep the final
executable small enough analyze with a disassembler, I've omitted
druntime/phobos.  Because of this, the example is very platform specific.  It
was made to work on the linux x86_64 platform.

--- build.sh
dmd -c -conf= -O -release -inline -betterC main.d object.d
ld -o main main.o object.o

--- object.d
module object;

alias size_t = ulong;
alias ptrdiff_t = long;

alias string = immutable(char)[];

--- main.d
pragma(inline)
int removeme(int x)
{
return x;
}

extern(C) int main(int argc, char*[] argv, char*[] envp)
{
sys_write(1, "running...\n".ptr, 11);
return removeme(0);
}

extern (C) ptrdiff_t sys_exit(int exitCode)
{
asm
{
naked;
mov EAX, 60;
}
}
extern (C) ptrdiff_t sys_write(int fd, const(char)* buf, size_t n)
{
asm
{
naked;
mov EAX, 1;
syscall;
ret;
}
}
extern (C) void _start()
{
asm
{
naked;
xor RBP,RBP;
pop RDI;
mov RSI,RSP;
mov RDX,RDI;
add RDX,1;
shl RDX, 3;
add RDX,RSP;
add RSP,-8;
and RSP, 0xFFF8;
call main;
mov RDI, RAX;  // syscall param 1 = RAX (return value of main)
mov RAX, 60;   // SYS_exit
syscall;
}
}


After running `./build.sh`, it should create the `main` executable.  You can
run it with `./main` and verify it prints "running'.  However, if you
disassemble it then you'll find that it does not remove the "removeme" function
that should have been inlined.

> objdump -d main

main: file format elf64-x86-64


Disassembly of section .text:

004000b0 <_D4main8removemeFiZi>:
  4000b0:   50  push   %rax
  4000b1:   48 89 f8mov%rdi,%rax
  4000b4:   59  pop%rcx
  4000b5:   c3  retq   
...

004000b8 :
  4000b8:   55  push   %rbp
  4000b9:   48 8b ecmov%rsp,%rbp
  4000bc:   ba 0b 00 00 00  mov$0xb,%edx
  4000c1:   be 10 01 40 00  mov$0x400110,%esi
  4000c6:   bf 01 00 00 00  mov$0x1,%edi
  4000cb:   e8 0c 00 00 00  callq  4000dc 
  4000d0:   31 c0   xor%eax,%eax
  4000d2:   5d  pop%rbp
  4000d3:   c3  retq   

004000d4 :
  4000d4:   b8 3c 00 00 00  mov$0x3c,%eax
  4000d9:   00 00   add%al,(%rax)
...

004000dc :
  4000dc:   b8 01 00 00 00  mov$0x1,%eax
  4000e1:   0f 05   syscall 
  4000e3:   c3  retq   

004000e4 <_start>:
  4000e4:   31 ed   xor%ebp,%ebp
  4000e6:   5f  pop%rdi
  4000e7:   48 89 e6mov%rsp,%rsi
  4000ea:   48 89 famov%rdi,%rdx
  4000ed:   48 83 c2 01 add$0x1,%rdx
  4000f1:   48 c1 e2 03 shl$0x3,%rdx
  4000f5:   48 01 e2add%rsp,%rdx
  4000f8:   48 83 c4 f8 add$0xfff8,%rsp
  4000fc:   48 83 e4 f8 and$0xfff8,%rsp
  400100:   e8 b3 ff ff ff  callq  4000b8 
  400105:   48 89 c7mov%rax,%rdi
  400108:   b8 3c 00 00 00  mov$0x3c,%eax
  40010d:   0f 05   syscall

--