Oops, I did a bad job of testing LH_Mouse's patch because I was trying to
judge whether a broken build of a program got worse.  It turns out his
patch made the build worse, causing undefined reference errors for
functions like StringCbLengthA that get defined in strsafe.h when compiled
as a part of a library.  It seems like GCC won't emit a symbol for a
function if you declared it as inline (which is not surprising).  This is
probably because of the issue I pointed out in the second paragraph of my
last email.

So I'm back to recommending just two options: merge my patch in or look
into it more and figure out what the right logic really is.

--David



On Sun, Apr 2, 2017 at 8:12 PM, David Grayson <[email protected]>
wrote:

> I just tested LH_Mouse's patch and it seems to work fine, so I am OK with
> using it instead of mine.
>
> However, that patch seems like it could be wrong too, since when strsafe.h
> is used to compile the library, all the library functions will have
> __inline in their declarations even though we are compiling them with the
> intent to make normal non-inline functions in a static library.
>
> Looking back at the original header, there are things that confuse me.
> The __STRSAFE_NO_INLINE macro should probably be renamed to
> __STRSAFE_NO_IMPL, because the main thing it does is to control whether the
> header file provides definitions of its functions or not.  The case I
> described above is a case where you want function definitions but you don't
> want __inline, so the naming of __STRSAFE_NO_INLINE is confusing.
>
> It also seems like the function prototypes should not depend on
> __CRT_STRSAFE_IMPL (as they do currently) or on __STRSAFE_NO_IMPL (as they
> do in LH_Mouse's patch).  They should depend on some global option that
> says whether the functions are inline functions defined in the header or
> whether they come from one of the MinGW libraries (the default).  Would
> __CRT__NO_INLINE be the global option I'm looking for?
>
> If someone wants to sort out the logic that would be cool, or just merge
> in either my patch or LH_Mouse's, since they both fix a bunch of compiler
> warnings.
>
> --David
>
>
> On Sun, Apr 2, 2017 at 11:12 AM, Liu Hao <[email protected]> wrote:
>
>> I'm afraid it isn't the correct fix. If the compiler says it is declared
>> and not defined, then it is declared and not defined.
>>
>> The inline definitions are provided when `__STRSAFE__NO_INLINE` is not
>> defined (see line 159 and 873), that is, when `__CRT__NO_INLINE` is defined
>> and `__CRT_STRSAFE_IMPL` is not defined (see line 15). However, we fail to
>> keep the consistency between these declarations and definitions. These
>> functions are declared as inline only when `__CRT_STRSAFE_IMPL` is not
>> defined. If only `__CRT__NO_INLINE` is defined, these functions would be
>> declared as inline while their inline definitions will not be provided.
>> Hence the warning.
>>
>> The proper way to fix this problem is checking the same condition on
>> lines 84, 94 and lines 159, 175, 873, etc. I have attached a new patch for
>> this issue. Please test.
>>
>> --
>> Best regards,
>> LH_Mouse
>>
>>
>>
>>
>>
>> From f2f652c023ad1320f69bd7d5f0d5c47376056869 <(737)%20605-6869> 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..66b5336f 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
>> +#ifndef __STRSAFE__NO_INLINE
>>  #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
>> +#ifndef __STRSAFE__NO_INLINE
>>  #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