[Issue 19720] New: const structs without explicit initializer are not usable in CTFE expressions
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Wed Mar  6 10:14:40 UTC 2019
    
    
  
https://issues.dlang.org/show_bug.cgi?id=19720
          Issue ID: 19720
           Summary: const structs without explicit initializer are not
                    usable in CTFE expressions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johannes.riecken at gmail.com
Code:
dmd -main -run -<<<'struct S {int i;}const S s;pragma(msg, s);'
Expected output:
S(0)
Actual output:
__stdin.d(1): Error: static variable s cannot be read at compile time
__stdin.d(1):        while evaluating pragma(msg, s)
Note that initializing explicitly using a struct initializer literal gives the
expected result:
dmd -main -run -<<<'struct S {int i;}const S s={};pragma(msg, s);'
S(0)
--
    
    
More information about the Digitalmars-d-bugs
mailing list