SWI-Prolog / packages-cpp

The SWI-Prolog C++ interface
29 stars 13 forks source link

Omit template-id in constructors for C++20 #80

Closed jamesjer closed 5 months ago

jamesjer commented 5 months ago

In C++20, a simple-template-id is no longer allowed as the declarator-id for constructors and destructors. See https://cplusplus.github.io/CWG/issues/2237.html for the rationale. Recent versions of gcc warn about this:

In file included from /builddir/build/BUILD/swipl-9.2.3/packages/cpp/test_cpp.cpp:63:
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:182:26: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
  182 |   explicit WrappedC<C_t>(C_t v)
      |                          ^~~
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:182:26: note: remove the ‘< >’
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:185:16: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
  185 |   WrappedC<C_t>(            const WrappedC<C_t>&) = default;
      |                ^
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:185:16: note: remove the ‘< >’
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:190:3: warning: template-id not allowed for destructor in C++20 [-Wtemplate-id-cdtor]
  190 |   ~WrappedC<C_t>() { }
      |   ^
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:190:3: note: remove the ‘< >’
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1670:45: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
 1670 |   explicit PlForeignContextPtr<ContextType>(PlControl handle)
      |                                             ^~~~~~~~~
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1670:45: note: remove the ‘< >’
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1674:35: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
 1674 |   PlForeignContextPtr<ContextType>(const PlForeignContextPtr<ContextType>&) = delete;
      |                                   ^
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1674:35: note: remove the ‘< >’
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1675:36: warning: template-id not allowed for constructor in C++20 [-Wtemplate-id-cdtor]
 1675 |   PlForeignContextPtr<ContextType>(PlForeignContextPtr<ContextType>&&) = delete;
      |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/swipl-9.2.3/packages/cpp/SWI-cpp2.h:1675:36: note: remove the ‘< >’
jamesjer commented 5 months ago

Okay, I added the PlUnwrapAsPtr change as well. I have not checked any version of gcc older than 12.2, for the record.

kamahen commented 5 months ago

If I read the rationale correctly, it's not necessary to remove the <...> from friend functions, but it probably does no harm either.

I've tested the changes with g++-11 (there doesn't seem to be a Debian package for g++-10, only gcc-10).