Skip to content

Commit

Permalink
fix(ustring): fix Cuda warnings (#3978)
Browse files Browse the repository at this point in the history
To my eyes, these two constructors look like they should be treated as
doing exactly the same thing:

    MyType()
        : mymember(...)
    { }

and

    MyType()
    {
       mymember = ...;
    }

But nvcc in Cuda mode says no, if the constructor is constexpr, the
former is okey dokey, but latter gives a warning. Fine, Cuda, whatver
you say.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz committed Sep 8, 2023
1 parent 616bf69 commit fbce7d5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/include/OpenImageIO/ustring.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,41 +814,41 @@ class OIIO_UTIL_API ustringhash {

/// Construct a ustringhash from a null-terminated C string (char *).
OIIO_DEVICE_CONSTEXPR explicit ustringhash(const char* str)
{
#ifdef __CUDA_ARCH__
// GPU: just compute the hash. This can be constexpr!
m_hash = Strutil::strhash(str);
: m_hash(Strutil::strhash(str))
#else
// CPU: make ustring, get its hash. Note that ustring ctr can't be
// constexpr because it has to modify the internal ustring table.
m_hash = ustring(str).hash();
: m_hash(ustring(str).hash())
#endif
{
}

OIIO_DEVICE_CONSTEXPR explicit ustringhash(const char* str, size_t len)
{
#ifdef __CUDA_ARCH__
// GPU: just compute the hash. This can be constexpr!
m_hash = Strutil::strhash(len, str);
: m_hash(Strutil::strhash(len, str))
#else
// CPU: make ustring, get its hash. Note that ustring ctr can't be
// constexpr because it has to modify the internal ustring table.
m_hash = ustring(str, len).hash();
: m_hash(ustring(str, len).hash())
#endif
{
}

/// Construct a ustringhash from a string_view, which can be
/// auto-converted from either a std::string.
OIIO_DEVICE_CONSTEXPR explicit ustringhash(string_view str)
{
#ifdef __CUDA_ARCH__
// GPU: just compute the hash. This can be constexpr!
m_hash = Strutil::strhash(str);
: m_hash(Strutil::strhash(str))
#else
// CPU: make ustring, get its hash. Note that ustring ctr can't be
// constexpr because it has to modify the internal ustring table.
m_hash = ustring(str).hash();
: m_hash(ustring(str).hash())
#endif
{
}

/// Construct from a raw hash value. Beware: results are undefined if it's
Expand Down

0 comments on commit fbce7d5

Please sign in to comment.