Re: DMD 2.092 and DIP 25
On Saturday, 30 May 2020 at 16:14:34 UTC, Steven Schveighoffer wrote: This is not about const or not, it's about lifetime management. For example, this would return a pointer to a stack frame that is about to go away: const(char)* foo() { ErrorInfo info; return info.message; } I know that you have already fixed the problem, but I wanted to make sure you understood why the compiler is complaining. Yes, that was me having never actually read DIP 25 and misunderstanding what it was about. I've since been educated. Thanks!
Re: DMD 2.092 and DIP 25
On 5/30/20 3:00 AM, Mike Parker wrote: The following declarations now give a deprecation warning: ```d struct ErrorInfo { private: char[32] _error; char[96] _message; public @nogc nothrow @property: /** Returns the string "Missing Symbol" to indicate a symbol load failure, and the name of a library to indicate a library load failure. */ const(char)* error() const { return _error.ptr; } /** Returns a symbol name for symbol load failures, and a system-specific error message for library load failures. */ const(char)* message() const { return _message.ptr; } } ``` I find it rather annoying, as I'm returning `const(char)*` and not `char*`, but it is what it is. My question is, if I add `return` to the function declarations, will this compile all the way back to DMD 2.067 *without* `-preview=dip25`? It works on 2.091.0. I always assumed a preview feature's syntax wasn't supported without the preview switch. I had to run the code to see the warning to understand what you meant. Here is the warning: onlineapp.d(11): Deprecation: returning _error escapes a reference to parameter this, perhaps annotate with return onlineapp.d(17): Deprecation: returning _message escapes a reference to parameter this, perhaps annotate with return This is not about const or not, it's about lifetime management. For example, this would return a pointer to a stack frame that is about to go away: const(char)* foo() { ErrorInfo info; return info.message; } I know that you have already fixed the problem, but I wanted to make sure you understood why the compiler is complaining. -Steve
Re: DMD 2.092 and DIP 25
On Saturday, 30 May 2020 at 07:30:17 UTC, Max Samukha wrote: On Saturday, 30 May 2020 at 07:00:07 UTC, Mike Parker wrote: https://run.dlang.io/is/aOZqww Since 2.067.1: Success and no output Thanks, Max (and you, too, Seb). I had forgotten that run.dlang.io supports compilers going so far back.
Re: DMD 2.092 and DIP 25
On Saturday, 30 May 2020 at 07:30:17 UTC, Max Samukha wrote: On Saturday, 30 May 2020 at 07:00:07 UTC, Mike Parker wrote: https://run.dlang.io/is/aOZqww Since 2.067.1: Success and no output Thanks! I forgot that run.dlang.io supports all those old compilers.
Re: DMD 2.092 and DIP 25
On Saturday, 30 May 2020 at 07:00:07 UTC, Mike Parker wrote: The following declarations now give a deprecation warning: ```d struct ErrorInfo { private: char[32] _error; char[96] _message; public @nogc nothrow @property: /** Returns the string "Missing Symbol" to indicate a symbol load failure, and the name of a library to indicate a library load failure. */ const(char)* error() const { return _error.ptr; } /** Returns a symbol name for symbol load failures, and a system-specific error message for library load failures. */ const(char)* message() const { return _message.ptr; } } ``` I find it rather annoying, as I'm returning `const(char)*` and not `char*`, but it is what it is. My question is, if I add `return` to the function declarations, will this compile all the way back to DMD 2.067 *without* `-preview=dip25`? It works on 2.091.0. I always assumed a preview feature's syntax wasn't supported without the preview switch. Return is actually pretty old, so it will compile: https://run.dlang.io/is/DgbYU9 Typically -preview flags are just looked at during the semantic phases. Another solution could be to turn the functions into templates and let the compiler do its attribute inference.
Re: DMD 2.092 and DIP 25
On Saturday, 30 May 2020 at 07:00:07 UTC, Mike Parker wrote: I find it rather annoying, as I'm returning `const(char)*` and not `char*`, but it is what it is. My question is, if I add `return` to the function declarations, will this compile all the way back to DMD 2.067 *without* `-preview=dip25`? It works on 2.091.0. I always assumed a preview feature's syntax wasn't supported without the preview switch. https://run.dlang.io/is/aOZqww Since 2.067.1: Success and no output
DMD 2.092 and DIP 25
The following declarations now give a deprecation warning: ```d struct ErrorInfo { private: char[32] _error; char[96] _message; public @nogc nothrow @property: /** Returns the string "Missing Symbol" to indicate a symbol load failure, and the name of a library to indicate a library load failure. */ const(char)* error() const { return _error.ptr; } /** Returns a symbol name for symbol load failures, and a system-specific error message for library load failures. */ const(char)* message() const { return _message.ptr; } } ``` I find it rather annoying, as I'm returning `const(char)*` and not `char*`, but it is what it is. My question is, if I add `return` to the function declarations, will this compile all the way back to DMD 2.067 *without* `-preview=dip25`? It works on 2.091.0. I always assumed a preview feature's syntax wasn't supported without the preview switch.