Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 15668 : __LINE__ evaluated at declaration context #5435

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -4916,9 +4916,13 @@ public:
istate = &istateComma;
}
result = CTFEExp.cantexp;

// If the comma returns a temporary variable, it needs to be an lvalue
// (this is particularly important for struct constructors)
if (e.e1.op == TOKdeclaration && e.e2.op == TOKvar && (cast(DeclarationExp)e.e1).declaration == (cast(VarExp)e.e2).var && (cast(VarExp)e.e2).var.storage_class & STCctfe) // same as Expression::isTemp
if (e.e1.op == TOKdeclaration &&
e.e2.op == TOKvar &&
(cast(DeclarationExp)e.e1).declaration == (cast(VarExp)e.e2).var &&
(cast(VarExp)e.e2).var.storage_class & STCctfe)
{
VarExp ve = cast(VarExp)e.e2;
VarDeclaration v = ve.var.isVarDeclaration();
Expand Down
4 changes: 2 additions & 2 deletions src/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ public:
* the oded == oarg
*/
(*dedargs)[i] = oded;
MATCH m2 = tparam.matchArg(loc, paramscope, dedargs, i, parameters, dedtypes, null);
MATCH m2 = tparam.matchArg(instLoc, paramscope, dedargs, i, parameters, dedtypes, null);
//printf("m2 = %d\n", m2);
if (m2 <= MATCHnomatch)
goto Lnomatch;
Expand All @@ -1453,7 +1453,7 @@ public:
}
else
{
oded = tparam.defaultArg(loc, paramscope);
oded = tparam.defaultArg(instLoc, paramscope);
if (oded)
(*dedargs)[i] = declareParameter(paramscope, tparam, oded);
}
Expand Down
2 changes: 1 addition & 1 deletion src/inline.d
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ void expandInline(FuncDeclaration fd, FuncDeclaration parent, Expression eret,
else
{
Identifier tmp = Identifier.generateId("__nrvoretval");
auto vd = new VarDeclaration(fd.loc, fd.nrvo_var.type, tmp, null);
auto vd = new VarDeclaration(fd.loc, fd.nrvo_var.type, tmp, new VoidInitializer(fd.loc));
assert(!tf.isref);
vd.storage_class = STCtemp | STCrvalue;
vd.linkage = tf.linkage;
Expand Down
8 changes: 8 additions & 0 deletions test/compilable/imports/imp15490a.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module imports.imp15490a;

import imports.imp15490b;

void listenTCP()
{
enum r = regex();
}
12 changes: 12 additions & 0 deletions test/compilable/imports/imp15490b.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module imports.imp15490b;

int regex()
{
return regexImpl();
}

auto regexImpl()
{
int r = 0;
return r;
}
12 changes: 12 additions & 0 deletions test/compilable/test15490.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// REQUIRED_ARGS: -o- -inline
// PERMUTE_ARGS:
module test15490;

import imports.imp15490a;
import imports.imp15490b;

void main()
{
regex();
listenTCP();
}
9 changes: 9 additions & 0 deletions test/compilable/test15668.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
void foo ( int line = __LINE__ ) ( string msg = "" )
{
static assert (line == 8);
}

void main()
{
foo();
}