Bug 3033 – CTFE call of non-static member function allowed inside template

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Linux
Creation time
2009-05-28T09:18:00Z
Last change time
2014-04-18T09:12:08Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
kamm-removethis

Comments

Comment #0 by kamm-removethis — 2009-05-28T09:18:02Z
From http://www.dsource.org/projects/ldc/ticket/312 The code --- struct Struct { Struct method() { return *this; } } template Template() { const CONST_STRUCT = Struct().method(); // A: no error } alias Template!() foo; const CONST_STRUCT2 = Struct().method(); // B: error --- correctly produces an error for line B "non-constant expression (Struct()).method()" (the CTFE spec says: "4. the function may not be a non-static member, i.e. it may not have a this pointer"), but doesn't for line A. Please either make both lines work and update the spec, or make A an error.
Comment #1 by clugdbug — 2009-08-17T02:24:21Z
This is invalid. The template never gets instantiated (certainly its value is never requested), so CTFE isn't involved. The alias is still OK, since it might be used at runtime. Try adding this line at the end: const CONST_STRUCT3 = foo.CONST_STRUCT; and then you'll correctly get an error.