D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1670 - tupleof an aggregate cannot be used as a template tuple argument
Summary: tupleof an aggregate cannot be used as a template tuple argument
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2007-11-15 08:53 UTC by Jarrett Billingsley
Modified: 2019-08-12 10:34 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jarrett Billingsley 2007-11-15 08:53:21 UTC
struct S
{
	int x;
}

class C
{
	int x;
}

union U
{
	int x;
}

alias Tuple!(S.tupleof) ST;
alias Tuple!(C.tupleof) CT;
alias Tuple!(U.tupleof) UT;

All of those instantiations give the error "Error: tuple is not a valid template value argument".  No, but I'd suppose being tuples that they'd be valid _tuple_ arguments, Mr. Compiler!
Comment 1 Michal Minich 2009-11-16 05:53:24 UTC
struct Point { int x; int y; }

void main ()
{
    Point p;
    
    mixin Foo!(p.x);               // works (prints "x" at compile time)

    mixin Foo!(Point.x);           // works (prints "x" at compile time)

    mixin Foo!(p.tupleof[0]);      // Error: expression (Point).x is not a valid template value argument (but still prints "(Point).x" at compile time)

    mixin Foo!(Point.tupleof[0]);  // Error: expression (Point).x is not a valid template value argument (but still prints "(Point).x" at compile time)
}

template Foo (alias a)
{
    pragma (msg, a.stringof);
}

Shouldn't p.x and p.tupleof[0] work the same way ?

tested on DMD 2.036
Comment 2 RazvanN 2019-08-12 10:34:49 UTC
This issue has been fixed in D2. Closing as WORKSFORME.