D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14166 - [REG2.066] Excess CTFE running for the temporary variable in module level expression
Summary: [REG2.066] Excess CTFE running for the temporary variable in module level exp...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2015-02-10 15:00 UTC by Vlad Levenfeld
Modified: 2015-02-21 09:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vlad Levenfeld 2015-02-10 15:00:21 UTC
In the following code, I expect the pragma to output "int". When static if (1) causes a null dereference in CTFE. Manually lowering (static if (0)) causes the code to behave as expected.

/////

struct Proxy (T)
{
	T* ptr;
	
	ref deref ()
	{
		return *ptr;
	}
	
	alias deref this;
}

struct Test
{
	auto opIndex ()
	{
		return this;
	}
	auto opIndex (int)
	{
		return 1;
	}
}

template Elem (R)
{
	static if (0) // 0 => Elem == int; 1 => Error: dereference of null pointer 'this.ptr'
		alias Elem = typeof(R.init[][0]);
	else alias Elem = typeof(R.init[].opIndex (0));
}

void main ()
{
	alias T = Proxy!Test;
	pragma (msg, Elem!T);
}


/*
dmd git-HEAD outputs this:

source/app.d(11): Error: dereference of null pointer 'this.ptr'
source/app.d(31):        called from here: Proxy(null).deref()
source/app.d(37): Error: template instance app.Elem!(Proxy!(Test)) error instantiating
source/app.d(37):        while evaluating pragma(msg, Elem!(Proxy!(Test)))
FAIL .dub/build/application-debug-linux.posix-x86_64-dmd_2067-905D3FE7D130796D902AA401E263BCF6/ testing executable
Error executing command run:
dmd failed with exit code 1.

*/
Comment 1 Kenji Hara 2015-02-10 15:19:29 UTC
Is this really a regression? With 2.066.1 and, 2.066, same error happens.

And with 2.065, the error is changed to:

test.d(28): Error: Test cannot be sliced with []
test.d(36): Error: template instance test.Elem!(Proxy!(Test)) error instantiating
test.d(36):        while evaluating pragma(msg, Elem!(Proxy!(Test)))

because multidimensional indexing/slicing operator overload is not yet supported.
Comment 2 Vladimir Panteleev 2015-02-10 15:28:23 UTC
(In reply to Kenji Hara from comment #1)
> Is this really a regression? With 2.066.1 and, 2.066, same error happens.
> 
> And with 2.065, the error is changed to:

Sorry about that. This code compiles in 2.065 but not 2.066:

////////////// test.d /////////////
struct Proxy (T)
{
    T* ptr;
    
    ref deref ()
    {
        return *ptr;
    }
    
    alias deref this;
}

struct Test
{
    auto opIndex ()
    {
        return this;
    }
    auto opIndex (int)
    {
        return 1;
    }
}

template Elem (R)
{
    alias Elem = typeof(R.init[0]);
}

void main ()
{
    alias T = Proxy!Test;
    pragma (msg, Elem!T);
}
///////////////////////////////////

Introduced in https://github.com/D-Programming-Language/dmd/pull/3569
Comment 3 Kenji Hara 2015-02-10 15:44:59 UTC
(In reply to Vladimir Panteleev from comment #2)
> (In reply to Kenji Hara from comment #1)
> > Is this really a regression? With 2.066.1 and, 2.066, same error happens.
> > 
> > And with 2.065, the error is changed to:
> 
> Sorry about that. This code compiles in 2.065 but not 2.066:
> 
[snip]

Thanks. I found that the root of the first rejects-valid case is same with the second regression case. But I want a little more time for the think of the good way to fix the issue.
Comment 5 github-bugzilla 2015-02-11 04:34:37 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/44a3c6377eb1a2ebc914b497b360c1459b9f1dad
fix Issue 14166 - Excess CTFE running for the temporary variable in module level expression

https://github.com/D-Programming-Language/dmd/commit/202871ccbcbe4fca09de4aaac99b7f808050a003
Merge pull request #4403 from 9rnsr/fix14166

[REG2.066] Issue 14166 - Excess CTFE running for the temporary variable in module level expression
Comment 6 github-bugzilla 2015-02-21 09:11:25 UTC
Commits pushed to https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/44a3c6377eb1a2ebc914b497b360c1459b9f1dad
fix Issue 14166 - Excess CTFE running for the temporary variable in module level expression

https://github.com/D-Programming-Language/dmd/commit/202871ccbcbe4fca09de4aaac99b7f808050a003
Merge pull request #4403 from 9rnsr/fix14166