Bug 2695 – pure functions can invoke impure function pointers

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-02-27T09:20:00Z
Last change time
2015-06-09T01:21:08Z
Keywords
accepts-invalid, patch
Assigned to
bugzilla
Creator
clugdbug

Attachments

IDFilenameSummaryContent-TypeSize
3342695patch.patchPatch for DMD2.029.text/plain853

Comments

Comment #0 by clugdbug — 2009-02-27T09:20:44Z
This compiles, and it shouldn't. Interestingly, if you replace 'pure' with 'nothrow', the code is correctly rejected. -------- static int nasty; int impure_evil_function(int x) { nasty++; return nasty; } pure int foo(int x) { int function(int) a = &impure_evil_function; return a(x); } --------
Comment #1 by clugdbug — 2009-04-22T03:30:44Z
Created attachment 334 Patch for DMD2.029. This patch also prevents pure functions from calling impure delegates. It (correctly) does not prevent them from assigning to impure function pointers/delegates -- it just mustn't call them. I've tested it with delegates/functions passed as parameters, as well as defined as variables; I've also tested it with template functions, and with structs defining opCall, and made sure it doesn't cause problems with variables defined in module scope.
Comment #2 by clugdbug — 2009-05-14T01:28:05Z
Fixed DMD2.030