Last active
December 3, 2017 14:58
-
-
Save Manuzor/81cc01d57543202d68eab5a84d944027 to your computer and use it in GitHub Desktop.
Missing implicit `nothrow` when `-betterC` is passed to dmd v2.077.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/+ | |
Scenario: | |
Compile this file with dmd v2.077.1 and -betterC and it will complain: | |
> dmd miniwin32.d -m64 -betterC | |
.\miniwin32.d(38): Error: function miniwin32.culprit is not nothrow | |
.\miniwin32.d(32): Error: nothrow function miniwin32.windowCallback may throw | |
Declaration of WNDCLASSA: | |
struct WNDCLASSA { | |
// ... | |
WNDPROC lpfnWndProc; | |
// ... | |
} | |
Definition of WNDPROC: | |
extern (Windows) nothrow { | |
// ... | |
alias LRESULT function(HWND, UINT, WPARAM, LPARAM) WNDPROC; | |
// ... | |
} | |
+/ | |
import core.sys.windows.windows; | |
pragma(lib, "User32.lib"); | |
// Uncomment the following line to fix the build. | |
//nothrow | |
bool culprit(UINT message) { return message == WM_CLOSE || message == WM_DESTROY; } | |
extern(Windows) nothrow | |
LRESULT windowCallback(HWND windowHandle, | |
UINT message, | |
WPARAM wParam, | |
LPARAM lParam) | |
{ | |
LRESULT result = 0; | |
if(culprit(message)) | |
{ | |
PostQuitMessage(0); | |
} | |
else | |
{ | |
result = DefWindowProcA(windowHandle, message, wParam, lParam); | |
} | |
return result; | |
} | |
extern(Windows) | |
int WinMain(HINSTANCE hInstance, | |
HINSTANCE hPrevInstance, | |
LPSTR lpCmdLine, | |
int nCmdShow) | |
{ | |
WNDCLASSA windowClass; | |
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; | |
windowClass.lpfnWndProc = &windowCallback; | |
windowClass.hInstance = hInstance; | |
windowClass.lpszClassName = "MiniWin32Class\0".ptr; | |
if(RegisterClassA(&windowClass)) | |
{ | |
DWORD windowStyleEx = 0; | |
DWORD windowStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE; | |
HWND windowHandle = | |
CreateWindowExA(windowStyleEx, // _In_ DWORD dwExStyle | |
windowClass.lpszClassName, // _In_opt_ LPCWSTR lpClassName | |
"Mini Win32\0".ptr, // _In_opt_ LPCWSTR lpWindowName | |
windowStyle, // _In_ DWORD dwStyle | |
CW_USEDEFAULT, CW_USEDEFAULT, // _In_ int X, Y | |
300, 300, // _In_ int nWidth, nHeight | |
null, // _In_opt_ HWND hWndParent | |
null, // _In_opt_ HMENU hMenu | |
hInstance, // _In_opt_ HINSTANCE hInstance | |
null); // _In_opt_ LPVOID lpParam | |
LOuter: while(true) | |
{ | |
MSG message; | |
while(PeekMessageA(&message, null, 0, 0, PM_REMOVE)) | |
{ | |
if(message.message == WM_QUIT) | |
{ | |
break LOuter; | |
} | |
TranslateMessage(&message); | |
DispatchMessageA(&message); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just to be clear, given
-betterC
, I would expect function declarations to implicitly have thenothrow
attribute. It makes no sense for the code to throw exceptions, because-betterC
disables them.