Bug 3573 – pure and nothrow allow function return type to be inferred

Status
RESOLVED
Resolution
WORKSFORME
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-12-04T02:39:00Z
Last change time
2017-07-09T12:36:45Z
Keywords
accepts-invalid
Assigned to
nobody
Creator
michal.minich

Comments

Comment #0 by michal.minich — 2009-12-04T02:39:36Z
there are 3 related problems: 1. it is possible to declare function without specifying return type. pure foo () {} pure foo () {} pure nothrow foo () {} should be: pure nothrow void foo () {} 2. pure is not enforced when return type is omitted int bar = 3; pure foo () { bar = 42; } void main () { writeln (bar); // writes 3 foo (); writeln (bar); // writes 42 } 3. nothrow is not enforced when return type is omitted nothrow foo () { throw new Exception (""); } void main () { foo (); // throws exception }
Comment #1 by clugdbug — 2010-12-08T04:39:43Z
Points 2 and 3 were fixed in DMD svn 736. Point 1 remains, though I don't think it can ever cause problems. Changing title and downgrading to minor. Original bug title: "pure and nothrow are not enforced when function has no return type specified"
Comment #2 by yebblies — 2013-11-16T23:08:31Z
*** Issue 11491 has been marked as a duplicate of this issue. ***
Comment #3 by qs.il.paperinik — 2016-09-16T13:33:57Z
Isn't 1. a feature?
Comment #4 by dlang-bugzilla — 2017-07-07T15:45:57Z
(In reply to Michal Minich from comment #0) > 1. it is possible to declare function without specifying return type. > > pure foo () {} > pure foo () {} > pure nothrow foo () {} These are now implied to have an "auto" return type, i.e.: pure foo () {} pure bar () { return 1; } pragma(msg, typeof(foo()).stringof); // prints "void" pragma(msg, typeof(bar()).stringof); // prints "int"