arcaneframework / framework

The Arcane Framework for HPC codes
https://arcaneframework.github.io/arcane/userdoc/html/index.html
Apache License 2.0
28 stars 14 forks source link

RefDeclarations.h generates lots of warnings in client code. Also does it realy works ? #1582

Closed guignont closed 3 weeks ago

guignont commented 1 month ago

The file arccore/src/base/arccore/base/RefDeclarations.h generates lots of warnings when compiling client code, exemple:

/work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/RefDeclarations.h:118:75: warning: l'opérande de gauche de l'opérateur virgule n'a pas d'effet [-Wunused-value] /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/RefDeclarations.h: Dans l'instanciation de « struct Arccore::impl::HasInternalAddReference<Arcane::CaseOptionMultiServiceImpl, int> » : /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/RefDeclarations.h:152:5: requis par « static void Arccore::ReferenceCounterAccessor::addReference(T) [with T = Arcane::CaseOptionMultiServiceImpl] » /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/ReferenceCounter.h:96:48: requis par « void Arccore::ReferenceCounter::_changeValue(T) [with T = Arcane::CaseOptionMultiServiceImpl] » /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/ReferenceCounter.h:58:70: requis par « Arccore::ReferenceCounter::ReferenceCounter(T*) [with T = Arcane::CaseOptionMultiServiceImpl] » /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arcane/core/CaseOptionService.h:265:58: requis depuis ici /work/guignont/work/ArcaneV3/framework/cmake-build-debug-arcane_gimkl2018b/_common/build_all/alien/ArcaneInterface/install/1.0.0/include/arccore/base/RefDeclarations.h:130:69: warning: l'opérande de gauche de l'opérateur virgule n'a pas d'effet [-Wunused-value] struct HasInternalAddReference<T, decltype(&T::_internalAddReference, 0)>



Also the structures HasInternalRemoveReference and HasInternalAddReference do realy work ?
a small exemple:

#include <iostream>
#include <vector>

template <typename T, typename = int>
struct HasDataMethod
  : std::false_type
{
};

template <typename T>
struct HasDataMethod<T, decltype(&T::data,0)>
  : std::true_type
{
};

class foo
{
};

int main() {
  std::cout << "vector has data "<<  HasDataMethod<std::vector<double>>::value << std::endl;
  std::cout << "foo has data "<<  HasDataMethod<foo>::value << std::endl;

  return 0;
}

Output is:
vector has data 0
foo has data 0

According to the intent we expect:
vector has data 1
foo has data 0

May be there is a problem with coma operator and expression "&T::data,0"  .
The type of this expression will be always the type of the last item (int in this case)
grospelliergilles commented 1 month ago

The warning is only with old version of GCC (before version 11). You can remove it using -Wno-Wunused-value during compilation.

The code using HasInternalRemoveReference and HasInternalAddReference works in Arccore. In your example, it does not work because you are using the method data() and this method is overloaded for std::vector so decltype(&T::data) is ambiguous and so it is not valid. If you use a method which is not overloaded (for example size()), it will works.

The above code is only for compatibility with previous versions of Arccore and will be removed in the future. When C++20 will be used everywhere I will replace it using concepts.

guignont commented 1 month ago

Thank you for the explanation