================ @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 %s -triple x86_64-windows -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify=windows +// RUN: %clang_cc1 %s -triple x86_64-windows -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -x c++ -verify=windows +// RUN: %clang_cc1 %s -triple x86_64-pc-linux -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -verify=linux +// RUN: %clang_cc1 %s -triple x86_64-pc-linux -fsyntax-only -Wcast-function-type -Wno-cast-function-type-strict -x c++ -verify=linux,linux-cpp +// RUN: %clang_cc1 %s -triple x86_64-windows -fsyntax-only -Wcast-function-type -Wcast-function-type-strict -x c++ -verify=strict +// windows-no-diagnostics + +// On Windows targets, this is expected to compile fine, and on non-Windows +// targets, this should diagnose the mismatch. This is to allow for idiomatic +// use of GetProcAddress, similar to what we do for dlsym. On non-Windows +// targets, this should be diagnosed. +typedef int (*FARPROC1)(); +typedef unsigned long long (*FARPROC2)(); + +FARPROC1 GetProcAddress1(void); +FARPROC2 GetProcAddress2(void); + +typedef int (*test1_type)(int); +typedef float(*test2_type)(); + +void test(void) { + // This does not diagnose on Linux in C mode because FARPROC1 has a matching + // return type to test1_type, but FARPROC1 has no prototype and so checking + // is disabled for further compatibility issues. In C++ mode, all functions + // have a prototype and so the check happens. + test1_type t1 = (test1_type)GetProcAddress1(); // linux-cpp-warning {{cast from 'FARPROC1' (aka 'int (*)()') to 'test1_type' (aka 'int (*)(int)') converts to incompatible function type}} \ ---------------- rnk wrote:
I do like @+1 syntax for readability, but that's a nice-to-have. https://github.com/llvm/llvm-project/pull/135660 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits