[Issue 19111] Returning a reference to local array results in garbage

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

Mike Franklin  changed:

   What|Removed |Added

   Keywords||safe
 CC||slavo5...@yahoo.com

--- Comment #1 from Mike Franklin  ---
Using `@safe` with `-dip1000` seems to catch the error:

import std.stdio;

@safe:

int[] makeRef(int[] a)
{
return a;
}

int[] getArray()
{
int[10] a;
a []= 42;
return makeRef(a);
}

void main()
{
writefln("%s",getArray());
}

$ dmd -dip1000 test.d

https://run.dlang.io/is/hIoDsB

onlineapp.d(14): Error: reference to local variable a assigned to non-scope
parameter a calling `onlineapp.makeRef`

--


[Issue 19111] New: Returning a reference to local array results in garbage

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

  Issue ID: 19111
   Summary: Returning a reference to local array results in
garbage
   Product: D
   Version: D2
  Hardware: All
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: a...@sunopti.com

See code below.
This is a reduction of a real life bug.
Arrays declared like int[10] a, appear to behave differently to auto a = new
int[10].
I can understand this might be intended for efficiency etc, but it is source of
undefined behaviour that I thought D design intent was to avoid.

In the below, the code can work as long as makeRef happens to modify the array
in a way that makes it need to reallocate the array on the heap.
If that doesn't happen, a reference is returned to the local variable.
With my previous understanding of how arrays were garbage collected, nice to
slice etc it is really not clear that it is possible to return a reference to a
locally declared variable that can go out of scope.

I suggest that int[10] should be on the heap unless the compiler can be sure
that there isn't a way for a reference to escape.
That way people writing high performance code that actually need a stack array
have to write code in a way that convinces the compiler not to promote it to
the stack, and everyone else gets the code that avoids undefined behavior.


import std.stdio;

int[] makeRef(int[] a)
{
a ~= 43;   //if this is removed the result of getArray contains
garbage.
return a;
}

int[] getArray()
{
int[10] a;
a []= 42;
//return a[0..3];   //Error: returning cast(int[])a escapes a
reference to local variable a
return makeRef(a);  //compiles without error, and returns garbage,
unless makeRef happens to modify a
}

void main()
{
writefln("%s",getArray());
}

--


[Issue 15246] Destructor inheritance doesn't inherit attributes properly

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

Andrei Alexandrescu  changed:

   What|Removed |Added

   Assignee|nob...@puremagic.com|razvan.nitu1...@gmail.com

--- Comment #20 from Andrei Alexandrescu  ---
Yah, the DIP should definitely amended to include ~this() on the list of
functions to look at. Assigning to Razvan so we don't forget about this.

--


[Issue 10233] [Tracker] Grammar issues

2018-07-22 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=10233
Issue 10233 depends on issue 13943, which changed state.

Issue 13943 Summary: Grammar does not list 'super' and 'this' as types
https://issues.dlang.org/show_bug.cgi?id=13943

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


[Issue 13943] Grammar does not list 'super' and 'this' as types

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

Basile B.  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||b2.t...@gmx.com
 Resolution|--- |FIXED

--


[Issue 19110] [internal] Provide interface for implementing vendor-specific pragmas

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

Iain Buclaw  changed:

   What|Removed |Added

 CC||ibuc...@gdcproject.org
   Assignee|nob...@puremagic.com|ibuc...@gdcproject.org

--


[Issue 19110] New: [internal] Provide interface for implementing vendor-specific pragmas

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

  Issue ID: 19110
   Summary: [internal] Provide interface for implementing
vendor-specific pragmas
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: ibuc...@gdcproject.org

The only way to add new vendor-specific pragmas is by modifying the front-end
sources.

Proposed:

/**
 * Checks whether the target/compiler supports the given pragma.
 * Params:
 *  ident = name of the pragma
 *  args  = arguments to pass to pragma
 *  statement = true if analysing a PragmaStatement.
 */
bool isPragmaSupported(Identifier ident, Expressions* args, bool statement)
{
// Implemented in Target::isPragmaSupported().
return false;
}


Example usage:

In dsymbolsem.d / statementsem.d:

else if (Target.isPragmaSupported(pd.ident, pd.args, false))
{
// Handled by backend.
}
else if (global.params.ignoreUnsupportedPragmas)
{
// Ignored on command-line.
}
else
pd.error("unrecognized pragma %s", pd.ident.toChars());

--


[Issue 19109] [SPEC] handling of unknown pragmas inconsistent with spec

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

Iain Buclaw  changed:

   What|Removed |Added

Summary|[SPEC] pragma   |[SPEC] handling  of unknown
   |implementation inconsistent |pragmas inconsistent with
   |with spec   |spec

--


[Issue 19072] Object.toHash and typeid(void*).getHash() should be more varied in their low bits

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

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

https://github.com/dlang/druntime/commit/710adf3f5d7d15f6024266a584de8ab1feb84fb3
Fix Issue 19072 - Object.toHash and typeid(void*).getHash() should be more
varied in their low bits

The low bits of Object.toHash are insufficiently varied. Depending on
the platform the bottom 4, 3, or 2 bits of the result will always be
zero. This is bad because the low bits of a hash code are typically the
most significant for hashtable implementations. D's builtin AA deals
with this and other potential defects by rehashing the hash codes it
receives. Some 3rd party hashtable implementations do the same, but
others assume that keys with a defined toHash have reasonable hashcodes
that can be used without need for further mixing.

Fixing this is not hard and not computationally expensive. This PR also
does a similar thing for raw pointers. Although it will not always be
necessary for them the cost is low and it will frequently be a benefit.

https://github.com/dlang/druntime/commit/b70774bc00a8e837eef05bbd2680ddc2fb2d62ea
Merge pull request #2247 from n8sh/object-hash-19072

Fix Issue 19072 - Object.toHash and typeid(void*).getHash() should be more
varied in their low bits
merged-on-behalf-of: Petar Kirov 

--


[Issue 19072] Object.toHash and typeid(void*).getHash() should be more varied in their low bits

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

github-bugzi...@puremagic.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--


[Issue 19109] [SPEC] pragma implementation inconsistent with spec

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

Iain Buclaw  changed:

   What|Removed |Added

 CC||ibuc...@gdcproject.org
   Assignee|nob...@puremagic.com|ibuc...@gdcproject.org

--


[Issue 19109] New: [SPEC] pragma implementation inconsistent with spec

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

  Issue ID: 19109
   Summary: [SPEC] pragma implementation inconsistent with spec
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: ibuc...@gdcproject.org

According to https://dlang.org/spec/pragma.html

```
Pragmas can appear as either declarations, Pragma DeclarationBlock, or as
statements, PragmaStatement.

---
1. pragma(ident);

2. pragma(ident) declaration_or_statement;

3. pragma(ident):
declaration;
declaration;

4. pragma(ident)
{
declaration_or_statement;
declaration_or_statement;
}
---
```

And yet item [2] doesn't seem to be the case, e.g:
```
pragma(msg, "test") // Error: missing a terminating ';'
void testA() { }

pragma(mangle, "test")  // But this is OK
void testB() { }

pragma(custom_pragma)// Error: missing a terminating ';'
void testC() { }
```
The third example above is of main concern regarding the discrepancy.  In the
first example, an error would be expected as that particular pragma is only
allowed as a statement by definition.

--


[Issue 19108] Unknown pragmas not ignored inside body

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

Iain Buclaw  changed:

   What|Removed |Added

 CC||ibuc...@gdcproject.org
   Assignee|nob...@puremagic.com|ibuc...@gdcproject.org

--


[Issue 19108] New: Unknown pragmas not ignored inside body

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

  Issue ID: 19108
   Summary: Unknown pragmas not ignored inside body
   Product: D
   Version: D2
  Hardware: All
OS: All
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: ibuc...@gdcproject.org

// dmd -ignore unknown_pragma.d

pragma(unknown_global);
void main()
{
pragma(unknown_local); // Error: unrecognized pragma
}

--


[Issue 10655] Error: recursive alias declaration

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

Simen Kjaeraas  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||simen.kja...@gmail.com
 Resolution|--- |WORKSFORME

--- Comment #1 from Simen Kjaeraas  ---
Works on 2.079.1 and 2.081.1 on windows.

--


[Issue 19107] New: -de produces compilation error, -dw does not

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

  Issue ID: 19107
   Summary: -de produces compilation error, -dw does not
   Product: D
   Version: D2
  Hardware: x86
OS: All
Status: NEW
  Severity: blocker
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: slavo5...@yahoo.com

--- sing.d
module sing;

alias I(alias A) = A;


--- git.d
import sing : I;


--- manager.d
module manager;

import std.algorithm;
import std.range;
import git;

class DManager
{
struct Config
{
struct Build
{
struct Components
{
string[] getEnabledComponentNames()
{
return null;
}
}
Components components;
}
Build build;
}
Config config;

void getCacheState(string[string] history)
{
auto componentNames = config.build.components.getEnabledComponentNames;
auto components = componentNames.map!(componentName => componentName);

components
.map!(component => component)
.map!(componentName => componentName);

foreach (submoduleCommits; history)
{
componentNames.all!(componentName => componentName.I!(component =>
component));
}
}
}

$ dmd -c -dw manager.d
OK

$ dmd -c -de manager.d
manager.d(37): Error: template
manager.DManager.getCacheState.__foreachbody5.all!((componentName) =>
componentName.I!((component) => component)).all cannot deduce function from
argument types !()(string[]), candidates are:
/usr/include/dlang/dmd/std/algorithm/searching.d(122):   
manager.DManager.getCacheState.__foreachbody5.all!((componentName) =>
componentName.I!((component) => component)).all(Range)(Range range) if
(isInputRange!Range && is(typeof(unaryFun!pred(range.front

Currently blocking progress on https://github.com/dlang/dmd/pull/8443

--


[Issue 19106] Make -lpthread -lm -lrt -ldl --as-needed on Linux target

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

Vic Luo  changed:

   What|Removed |Added

 CC||viclu...@gmail.com

--


[Issue 19106] New: Make -lpthread -lm -lrt -ldl --as-needed on Linux target

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

  Issue ID: 19106
   Summary: Make -lpthread -lm -lrt -ldl --as-needed on Linux
target
   Product: D
   Version: D2
  Hardware: All
OS: Linux
Status: NEW
  Severity: enhancement
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: viclu...@gmail.com

Current implementation links these libraries under all circumstances. However,
for libc-free programming these libraries are redundant. This is one of the
show stoppers toward `dmd`-based libc-free programming without invoking `cc`
manually. Another is https://github.com/dlang/dmd/pull/794.

Related code:
https://github.com/dlang/dmd/blob/6371942b1bf26dc6c65cc7e0668bc82e1974c18d/src/dmd/link.d#L652

--


[Issue 19105] New: Bogus recursive template expansion via getSymbolsByUDA

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

  Issue ID: 19105
   Summary: Bogus recursive template expansion via getSymbolsByUDA
   Product: D
   Version: D2
  Hardware: x86_64
OS: Linux
Status: NEW
  Severity: normal
  Priority: P1
 Component: dmd
  Assignee: nob...@puremagic.com
  Reporter: bus_dlangzi...@semitwist.com

-
module junk;

import std.traits;

struct A(Args...) {}
struct B {}
alias C = A!( getSymbolsByUDA!(junk, B) );
-

$ dmd junk.d
junk.d(7): Error: template instance `A!(getSymbolsByUDA!(junk, B))` recursive
template expansion
junk.d(7): Error: alias `junk.C` recursive alias declaration

--