project-gemmi / gemmi

macromolecular crystallography library and utilities
https://project-gemmi.github.io/
Mozilla Public License 2.0
205 stars 42 forks source link

Several warnings when compiling with nvcc #271

Closed correaa closed 1 year ago

correaa commented 1 year ago

When compiling with nvcc (11.8), several warnings are triggered:

(in my experience this type of warning happens when trying to define conversion operators that explicitly or accidentally convert to base classes)

/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(60): warning #554-D: "gemmi::StrideIterPolicy<Value>::operator gemmi::StrideIterPolicy<const std::string>() const [with Value=const std::string]" will not be called for implicit or explicit conversions
          detected during:
            instantiation of class "gemmi::StrideIterPolicy<Value> [with Value=const std::string]" 
(23): here
            instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::StrideIterPolicy<const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(202): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(42): warning #554-D: "gemmi::BidirIterator<Policy>::operator gemmi::BidirIterator<gemmi::StrideIterPolicy<const std::string>>() const [with Policy=gemmi::StrideIterPolicy<const std::string>]" will not be called for implicit or explicit conversions
          detected during instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::StrideIterPolicy<const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(202): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(83): warning #554-D: "gemmi::IndirectIterPolicy<Redirect, Value>::operator gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>() const [with Redirect=const gemmi::cif::Table::Row, Value=const std::string]" will not be called for implicit or explicit conversions
          detected during:
            instantiation of class "gemmi::IndirectIterPolicy<Redirect, Value> [with Redirect=const gemmi::cif::Table::Row, Value=const std::string]" 
(23): here
            instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(301): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(42): warning #554-D: "gemmi::BidirIterator<Policy>::operator gemmi::BidirIterator<gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>>() const [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" will not be called for implicit or explicit conversions
          detected during instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(301): here
[ 88%] Linking CUDA device code CMakeFiles/graphene.dir/cmake_device_link.o
cd /builds/correaa/boost-multi/inq/build/tests && /usr/bin/cmake -E cmake_link_script CMakeFiles/graphene.dir/dlink.txt --verbose=0
[ 88%] Linking CUDA device code CMakeFiles/h2o_ground_state.dir/cmake_device_link.o
cd /builds/correaa/boost-multi/inq/build/tests && /usr/bin/cmake -E cmake_link_script CMakeFiles/h2o_ground_state.dir/dlink.txt --verbose=0
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(60): warning #554-D: "gemmi::StrideIterPolicy<Value>::operator gemmi::StrideIterPolicy<const std::string>() const [with Value=const std::string]" will not be called for implicit or explicit conversions
          detected during:
            instantiation of class "gemmi::StrideIterPolicy<Value> [with Value=const std::string]" 
(23): here
            instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::StrideIterPolicy<const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(202): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(42): warning #554-D: "gemmi::BidirIterator<Policy>::operator gemmi::BidirIterator<gemmi::StrideIterPolicy<const std::string>>() const [with Policy=gemmi::StrideIterPolicy<const std::string>]" will not be called for implicit or explicit conversions
          detected during instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::StrideIterPolicy<const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(202): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(83): warning #554-D: "gemmi::IndirectIterPolicy<Redirect, Value>::operator gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>() const [with Redirect=const gemmi::cif::Table::Row, Value=const std::string]" will not be called for implicit or explicit conversions
          detected during:
            instantiation of class "gemmi::IndirectIterPolicy<Redirect, Value> [with Redirect=const gemmi::cif::Table::Row, Value=const std::string]" 
(23): here
            instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(301): here
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/iterator.hpp(42): warning #554-D: "gemmi::BidirIterator<Policy>::operator gemmi::BidirIterator<gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>>() const [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" will not be called for implicit or explicit conversions
          detected during instantiation of class "gemmi::BidirIterator<Policy> [with Policy=gemmi::IndirectIterPolicy<const gemmi::cif::Table::Row, const std::string>]" 
/builds/correaa/boost-multi/inq/external_libs/gemmi/include/gemmi/cifdoc.hpp(301): here
wojdyr commented 1 year ago

Apparently nvcc warning 544-D is the same as icc warning 597, which is disabled here: https://github.com/project-gemmi/gemmi/blob/master/include/gemmi/iterator.hpp#L13

If you know what ifdefs/pragmas to use for nvcc, I'll add it.

correaa commented 1 year ago

Yes, here it is for nvcc, nvc++ and intel

#if defined __INTEL_COMPILER or defined __NVCOMPILER
    #pragma    diagnostic push
    #pragma    diag_suppress = conversion_function_not_usable
#elif defined __NVCC__
    #pragma nv_diagnostic push
    #pragma nv_diag_suppress = conversion_function_not_usable
#endif

   ... offending conversion code

#if defined __INTEL_COMPILER or defined __NVCOMPILER
    #pragma    diagnostic pop
#elif defined __NVCC__
    #pragma nv_diagnostic pop
#endif

tests: https://godbolt.org/z/3hade8vKf

https://godbolt.org/z/P14ohjToY

correaa commented 1 year ago

I also had this problem in my own library, also when implementing iterators. At the time, I thought it was a reasonable warning so I decided to change the design to funnel conversion through constructors and class friendship.

For example https://gitlab.com/correaa/boost-multi/-/blob/master/include/multi/array_ref.hpp#L1596-1599

That perhaps added too much code and I am not so sure now if the warning was justified.

wojdyr commented 1 year ago

Thanks! I changed it as you proposed. TIL about diag_suppress.