Hi, when compiling GiNaC (latest version from git master) with MSVC (19.29.30139 for x64) it stumbles over the following code in lst.h/lst.cpp: lst.h line 35: template<> registered_class_info lst::reg_info; lst.cpp line 28: template <> GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func<print_context>(&lst::do_print). print_func<print_tree>(&lst::do_print_tree)) and says: lst.cpp(28): error C2766: explicit specialization; 'reg_info' has already been defined exprseq.h/.cpp has the same issue. A solution seems to be to remove the code in lst.cpp and replace the code in lst.h with it. That is lst.h: template <> GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func<print_context>(&lst::do_print). print_func<print_tree>(&lst::do_print_tree)) This compiles fine and all checks pass, but it does seem wrong to have the GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T in a header file. What is the right way to deal with this error? Thanks, Jan Rheinländer
Hi Jan, On 13.02.22 21:39, Jan Rheinländer wrote:
when compiling GiNaC (latest version from git master) with MSVC (19.29.30139 for x64) it stumbles over the following code in lst.h/lst.cpp:
I don't use MSVC. When was that compiler version released, approximately? (I am of course hoping this is already fixed.)
lst.h line 35: template<> registered_class_info lst::reg_info;
lst.cpp line 28: template <> GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func<print_context>(&lst::do_print). print_func<print_tree>(&lst::do_print_tree))
and says:
lst.cpp(28): error C2766: explicit specialization; 'reg_info' has already been defined
exprseq.h/.cpp has the same issue.
A solution seems to be to remove the code in lst.cpp and replace the code in lst.h with it. That is
lst.h: template <> GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func<print_context>(&lst::do_print). print_func<print_tree>(&lst::do_print_tree))
This compiles fine and all checks pass, but it does seem wrong to have the GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T in a header file.
What is the right way to deal with this error?
We discussed this a year ago: https://www.ginac.de/pipermail/ginac-devel/2021-February/002539.html Does this shed some light on the issue? -richy.
Hi Richard, that was MSVC from Visual Studio 2019. But the same happens with 19.30.30706 from VS 2022. Also, past experience shows that MSVC is very strict (you might say pedantic) about the standard. So I have little hope that the problem will go away with a new version of MSVC. The help page for error 2766 <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2766?view=msvc-170> says "Duplicate explicit specializations are not allowed". Though looking at the thread <https://www.ginac.de/pipermail/ginac-devel/2021-February/002539.html> you cited it would seem that the code in the header should be viewed as a declaration, not a definition: />> According to 14.7.3.13 />>/"An explicit specialization of a static data member of a template is />>/a definition if the declaration includes an initializer; otherwise, />>/it's a declaration."/ On the other hand, looking at structure.h, it does assign a value to reg_info in the header file. So maybe the solution I suggested (move GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T to the header) is not that bad after all? structure.h line 242: template <class T, template <class> class CP> registered_class_info structure<T, CP>::reg_info = registered_class_info(registered_class_options(structure::get_class_name(), "basic", typeid(structure<T, CP>))); Jan
Hello Jan, On 14.02.22 20:31, Jan Rheinländer wrote:
that was MSVC from Visual Studio 2019. But the same happens with 19.30.30706 from VS 2022. Also, past experience shows that MSVC is very strict (you might say pedantic) about the standard. So I have little hope that the problem will go away with a new version of MSVC.
Can you produce a stripped-down example and file a bug report against MSVC at Microsoft, please?
The help page for error 2766 <https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2766?view=msvc-170> says "Duplicate explicit specializations are not allowed". Though looking at the thread <https://www.ginac.de/pipermail/ginac-devel/2021-February/002539.html> you cited it would seem that the code in the header should be viewed as a declaration, not a definition:
/>> According to 14.7.3.13 />>/"An explicit specialization of a static data member of a template is />>/a definition if the declaration includes an initializer; otherwise, />>/it's a declaration."/
I cannot add anything to the standard section you cite. According to my reading and understanding, MSVC is confused if it thinks this is a definition.
On the other hand, looking at structure.h, it does assign a value to reg_info in the header file. So maybe the solution I suggested (move GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T to the header) is not that bad after all?
Can't we just #ifdef out the declaration for MSVC? -richy.
participants (2)
-
Jan Rheinländer
-
Richard B. Kreckel