sofa-framework / sofa

Real-time multi-physics simulation with an emphasis on medical simulation.
https://www.sofa-framework.org
GNU Lesser General Public License v2.1
910 stars 310 forks source link

Problem with fixed_array and static_assert in VisualStudio 2015 #130

Closed damienmarchal closed 6 years ago

damienmarchal commented 7 years ago

Hi all,

for the PR # https://github.com/sofa-framework/sofa/pull/119 implementing a basic RGBAColor i'm inheriting from Vec4f. This seems to fail on VS compiler.

The resulting error on VS2015 is the following (the static_asserts): https://ci.inria.fr/sofa-ci/job/windows7_VS-2015_default_amd64/1002/console

This seems to suggest that the templated code is 'generated' while it shouldn't.

Any help is welcome.

bcarrez commented 7 years ago

After spending some (too much?) time on this topic, it seems that the fact that static_assert not being evaluated in uninstantiated functions of template classes is not consistent between compilers. Neither could I find a way to trick the compiler to postpone the evaluation of the condition of the static_assert (for example replace (N==10) by (sizeof(T)==0||N==10) , of template tricks to force the compiler to wait for template instantiation before assertion evaluation.

All this is also true for BOOST_STATIC_ASSERT (tried this with no chance, too)

My opinion would be to simply remove the static_asserts, since in this context their behaviour is not specified by C++ references (and not consistent). We loose the benefit of the safeguard but are not subject to false-positive anymore. If anyone sees another solution...

damienmarchal commented 7 years ago

I haven't enough knowledge on that to be of anyhelp but maybe @JeremieA has.

damienmarchal commented 7 years ago

Hi all,

I don't like to removing the safeguard by removing the 'static_assert' I finally implemented a version in PR119 that conditionally compile the set(...,...) functions based on condition so that static_assert is not a problem anymore. The implementation is using the enable_if feature for C++X11.

damienmarchal commented 6 years ago

The PR seems to be fixed in #119 so it is close.