[Piglit] [PATCH 3/3] util: Fix `cannot convert from 'const char *' to 'char *'` MSVC error.

Jan Vesely jan.vesely at rutgers.edu
Wed Dec 3 14:26:17 PST 2014


On Wed, 2014-12-03 at 15:37 +0000, Jose Fonseca wrote:
> From: José Fonseca <jfonseca at vmware.com>
> 
> When in C++ mode, MSVC defines overloaded versions of standard names
> that preserve constness. :-/
> 
> http://msdn.microsoft.com/en-us/library/b34ccac3.aspx
> ---
>  tests/util/piglit-util.h | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 099075a..af9fb97 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -211,7 +211,11 @@ strtod_inf(const char *nptr, char **endptr)
>  static inline char *
>  strchrnul(const char *s, int c)
>  {
> +#if defined(_MSC_VER) && defined(__cplusplus)
> +	char *t = strchr((char *)s, c);

shouldn't the above version work in all cases? Implicit conversion to
const should be ok with other compilers, or am I missing something?

jan

> +#else
>  	char *t = strchr(s, c);
> +#endif
>  
>  	return (t == NULL) ? ((char *) s + strlen(s)) : t;
>  }

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20141203/6f1286c7/attachment.sig>


More information about the Piglit mailing list