I looked into it a little more.

__NO_INLINE__ is a macro provided by GCC that is documented to be defined
if "no functions will be inlined into their callers".  This seems to be
defined by GCC by default, but it is not defined when you provide the "-O2"
option.

__CRT__NO_INLINE is defined in mingw-w64-headers/crt/_mingw.h.in if
__NO_INLINE__ is defined (with an exception for Cygwin for some reason).
So the reasoning seems to be that we want our header files to have inline
definitions if GCC will actually perform inlining, and otherwise we want to
use the library versions.  I'm not sure why this is done, but it might make
unoptimized programs smaller and faster to compile.

__STRSAFE__NO_INLINE is defined at the beginning of strsafe.h and says
whether the header file is going to have function definitions or not.  We
want to have strsafe function definitions if GCC will perform inlining *or*
we are compiling the mingwex library.  So we *don't* want to have strsafe
function definitions if GCC will *not* perform inlining *and* we are *not*
compiling the mingwex library.  The logic for __STRSAFE__NO_INLINE in the
header file is correct, but the name of that macro is confusing.

STRSAFEAPI, STRSAFEAPIV, and STRSAFE_INLINE_API are macros used for
function declarations and definitions in strsafe.h.  It seems to me that we
should inline in STRSAFEAPI* if GCC will inline and we are not compiling
the mingwex library.  That's exactly what LH_Mouse's second patch does.

I'm a bit confused about the different inlining keywords.  From the GCC
documentation for inlining in the C language (
https://gcc.gnu.org/onlinedocs/gcc/Inline.html ) it seemed like "extern
inline" (i.e. __CRT_INLINE) would be the best thing to use, but I could not
find any cases where __inline (which I think is a macro) is worse.
LH_Mouse's patch does not change what kind of inlining keywords are used,
it just changes the logic for when to use those keywords.

Anyway, I tested LH_Mouse's second patch and it works for me, so I'd say
it's mergeable.

--David


On Mon, Apr 3, 2017 at 12:37 AM, Liu Hao <[email protected]> wrote:

> 1. Neither is defined. This is the case for our users. All functions are
> declared as inline and inline definitions are provided. So it is OK.


> 2. `__STRSAFE__NO_INLINE` is defined while `__CRT_STRSAFE_IMPL` is not.
> This is the case for your problem. All functions are declared inline but
> inline definitions are not provided, resulting in warnings about 'inline
> functions declared but never defined'.
>
> 3. `__CRT_STRSAFE_IMPL` is defined. Inline definitions are provided for
> calls to external functions. The functions must not be declared as inline
> in this case. That is why my previous patch failed. Apologies for that.
>
> New patch attached.
>
>
> --
> Best regards,
> LH_Mouse
>
>
>
> From f1c12fd9f35525ca3569c3427f953afb10b47588 Mon Sep 17 00:00:00 2001
> From: Liu Hao <[email protected]>
> Date: Mon, 3 Apr 2017 02:00:15 +0800
> Subject: [PATCH] include/strsafe.h: Fix warning 'inline function declared
> but
>  never defined'.
>
> Reference: https://sourceforge.net/p/mingw-w64/mailman/message/35763431/
> Signed-off-by: Liu Hao <[email protected]>
> ---
>  mingw-w64-headers/include/strsafe.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mingw-w64-headers/include/strsafe.h
> b/mingw-w64-headers/include/strsafe.h
> index 36c7796c..74f924ab 100644
> --- a/mingw-w64-headers/include/strsafe.h
> +++ b/mingw-w64-headers/include/strsafe.h
> @@ -81,7 +81,7 @@ typedef __LONG32 HRESULT;
>  #endif
>  #endif
>
> -#ifndef __CRT_STRSAFE_IMPL
> +#if !defined(__CRT__NO_INLINE) && !defined(__CRT_STRSAFE_IMPL)
>  #define STRSAFEAPI _STRSAFE_EXTERN_C __inline HRESULT WINAPI
>  /* Variadic functions can't be __stdcall.  */
>  #define STRSAFEAPIV _STRSAFE_EXTERN_C __inline HRESULT
> @@ -91,7 +91,7 @@ typedef __LONG32 HRESULT;
>  #define STRSAFEAPIV HRESULT
>  #endif
>
> -#ifndef __CRT_STRSAFE_IMPL
> +#if !defined(__CRT__NO_INLINE) && !defined(__CRT_STRSAFE_IMPL)
>
>  #define STRSAFE_INLINE_API _STRSAFE_EXTERN_C __CRT_INLINE HRESULT WINAPI
>  #else
>  #define STRSAFE_INLINE_API HRESULT WINAPI
> --
> 2.12.1
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to