Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #312 (closed defect: invalid)

Opened 15 years ago

Last modified 15 years ago

CTFE fails on struct method call

Reported by: klickverbot Assigned to: ChristianK
Priority: major Milestone:
Component: unspecified Version: hg tip
Keywords: Cc:

Description

LDC fails to compile the following code (the contents of Struct#method are not relevant):

struct Struct {
   static Struct opCall( float value ) {
      Struct newStruct;
      newStruct.value = value;
      return newStruct;
   }
 
   Struct method() {
      return *this;
   }
 
   float value;
}
 
template Template( float value ) {
   const CONST_STRUCT = Struct( value ).method();
}
 
void main( char[][] args ) {
   alias Template!( 1 ) foo;
}

Error message: Main.d(18): Error: expression '(Struct(1F)).method()' is not a constant

Version info: LLVM D Compiler based on DMD v1.045 and llvm 2.6svn (Wed May 27 00:08:12 2009)

Change History

05/28/09 16:07:20 changed by ChristianK

  • status changed from new to closed.
  • resolution set to invalid.

Thanks for the report - the code does indeed compile with DMD but fail with LDC. However, the CTFE spec says "4. the function may not be a non-static member, i.e. it may not have a this pointer" and thus I argue that the code is invalid.

If you replace the template and main in your testcase by

const CONST_STRUCT = Struct( 1.0 ).method();

and try to compile with DMD, you get "Error: non-constant expression (Struct(1F)).method()". So it seems to be unsure about the validity too. I'll check bugzilla for a bug.

05/28/09 16:18:43 changed by ChristianK

Copyright © 2008, LDC Development Team.