Bug 7570 – Missing error in ctfe for dereferencing a pointer passed as a parameter

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-02-24T05:05:00Z
Last change time
2015-07-09T04:06:31Z
Keywords
CTFE, rejects-valid
Assigned to
clugdbug
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-02-24T05:05:19Z
This may be wrong D2 code, if DMD is not able to run it at compile-time: bool not_end(const char *s, const int n) { return s && s[n]; } bool str_prefix(const char *s, const char *t, const int ns, const int nt) { return (s == t) || !*(t + nt) || (*(s + ns) == *(t + nt) && (str_prefix(s, t, ns+1, nt+1))); } bool contains(const char *s, const char *needle, const int n=0) { return not_end(s, n) && (str_prefix(s, needle, n, 0) || contains(s, needle, n+1)); } enum int x = contains("froogler", "oogle"); void main() {} DMD 2.059head gives no true error message, just some "called from here": bug.d(8): called from here: str_prefix(s,needle,n,0) bug.d(10): called from here: contains("froogler","oogle",0) bug.d(8): called from here: str_prefix(s,needle,n,0) bug.d(10): called from here: contains("froogler","oogle",0) bug.d(8): called from here: str_prefix(s,needle,n,0) bug.d(10): called from here: contains("froogler","oogle",0)
Comment #1 by yebblies — 2012-02-24T05:43:47Z
The interpreter can't seem to handle '!*(t + nt)', as constfold.c's Ptr only handles TOKaddress + TOKint64, and it resolves to TOKvar + TOKint64, and PtrExp::interpret doesn't handle the case where Ptr fails.
Comment #2 by clugdbug — 2012-03-02T06:20:59Z
Reduced test case: ======================================== bool contains(const char *s) { return *(s + 0) == 'a'; } static assert(!contains("froogler"));
Comment #3 by yebblies — 2013-01-16T07:11:46Z
Now fails with: DMD v2.062 DEBUG testx.d(4): called from here: contains("froogler") testx.d(4): Error: static assert (!contains("froogler")) is not evaluatable at compile time
Comment #4 by bearophile_hugs — 2013-01-16T10:08:45Z
I remove the diagnostic tag because the diagnostic now seems acceptable.
Comment #5 by k.hara.pg — 2015-07-09T04:06:31Z
Seems fixed in 2.067.