swipl-devel icon indicating copy to clipboard operation
swipl-devel copied to clipboard

Lots of warnings when compiling against C++ interface

Open wouterbeek opened this issue 5 years ago • 2 comments
trafficstars

A bit of a nitpick, but when I compile against the SWI Prolog C++ library I receive a lot of warnings. The list of warnings is so long that I am either likely to miss warnings in my own code or have to switch off some compiler flags. The flags that I use are not all that special, e.g., they do not include -Wpedantic. Here are the exact flags that I use:

CXXFLAGS+=-g --std=c++17 -Wall -Wextra

For a concrete example, this is the output when I compile one of my libraries against the SWI-Prolog C++ library:

Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:29: note:   initializing argument 2 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |                      ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:330:32: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   330 |       PlTermv(expected, actual)),
Warning:       |                                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlDomainError::PlDomainError(const char*, PlTerm)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:346:36: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   346 |            PlTermv(expected, actual)),
Warning:       |                                    ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:29: note:   initializing argument 2 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |                      ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:347:16: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   347 |        PlTerm())))
Warning:       |                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlInstantiationError::PlInstantiationError(const PlTerm&)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:361:7: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   361 |      t)) : t) {}
Warning:       |       ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:29: note:   initializing argument 2 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |                      ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:361:12: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   361 |      t)) : t) {}
Warning:       |            ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:361:12: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   361 |      t)) : t) {}
Warning:       |            ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlExistenceError::PlExistenceError(const char*, PlTerm)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:381:32: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   381 |            PlTermv(type, actual)),
Warning:       |                                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:29: note:   initializing argument 2 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |                      ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:382:16: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   382 |        PlTerm())))
Warning:       |                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlPermissionError::PlPermissionError(const char*, const char*, PlTerm)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:397:33: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   397 |            PlTermv(op, type, obj)),
Warning:       |                                 ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:238:40: note:   initializing argument 3 of 'PlTermv::PlTermv(PlTerm, PlTerm, PlTerm)'
Warning:   238 |   PlTermv(PlTerm m0, PlTerm m1, PlTerm m2);
Warning:       |                                 ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:398:16: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   398 |        PlTerm())))
Warning:       |                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlResourceError::PlResourceError(const char*)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:415:16: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   415 |        PlTerm())))
Warning:       |                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlTermvDomainError::PlTermvDomainError(int, int)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:430:28: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   430 |             PlTerm((long)n))),
Warning:       |                            ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:431:16: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   431 |        PlTerm())))
Warning:       |                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:237:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm, PlTerm)'
Warning:   237 |   PlTermv(PlTerm m0, PlTerm m1);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In function 'int PlCall(const char*)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:703:45: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   703 | { PlQuery q("call", PlTermv(PlCompound(goal)));
Warning:       |                                             ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:236:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm)'
Warning:   236 |   PlTermv(PlTerm m0);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In function 'int PlCall(const wchar_t*)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:709:45: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   709 | { PlQuery q("call", PlTermv(PlCompound(goal)));
Warning:       |                                             ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:236:18: note:   initializing argument 1 of 'PlTermv::PlTermv(PlTerm)'
Warning:   236 |   PlTermv(PlTerm m0);
Warning:       |           ~~~~~~~^~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In constructor 'PlAtom::PlAtom(const PlTerm&)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:726:32: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   726 |     throw PlTypeError("atom", t);
Warning:       |                                ^
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
Warning:   173 |   int operator =(const PlTerm &t2); /* term */
Warning:       |       ^~~~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:325:44: note:   initializing argument 2 of 'PlTypeError::PlTypeError(const char*, PlTerm)'
Warning:   325 |   PlTypeError(const char *expected, PlTerm actual) :
Warning:       |                                     ~~~~~~~^~~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h: In member function 'PlTerm PlTerm::operator[](size_t) const':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:813:12: warning: implicitly-declared 'constexpr PlTerm::PlTerm(const PlTerm&)' is deprecated [-Wdeprecated-copy]
Warning:   813 |     return t;
Warning:       |            ^
% /usr/local/lib/swipl/include/SWI-cpp.h:173:7: note: because 'PlTerm' has user-provided 'int PlTerm::operator=(const PlTerm&)'
%   173 |   int operator =(const PlTerm &t2); /* term */
%       |       ^~~~~~~~
Warning: cpp/geo.cpp: In function 'foreign_t pl_geo_halt___0(PlTermv)':
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:1295:54: warning: unused parameter 'PL_av' [-Wunused-parameter]
Warning:  1295 |  static foreign_t pl_ ## name ## __ ## arity(PlTermv PL_av)
Warning:       |                                              ~~~~~~~~^~~~~
Warning: /usr/local/lib/swipl/include/SWI-cpp.h:1333:39: note: in expansion of macro 'NAMED_PREDICATE'
Warning:  1333 | #define PREDICATE(name, arity)        NAMED_PREDICATE(#name, name, arity)
Warning:       |                                       ^~~~~~~~~~~~~~~

wouterbeek avatar May 15 '20 18:05 wouterbeek

This needs a C++ expert.

JanWielemaker avatar May 21 '20 15:05 JanWielemaker

Most of these warnings should be able to be fixed by adding a user-defined copy-constructor for PlTerm. It's basically complaining that, since you have defined a non-default operator=(const PlTerm &), that it is probably dangerous to rely on an implicitly defined copy constructor. Future versions of C++ will be deprecating implicitly declared copy constructors when a user-defined copy assignment operator is declared.

The later "unused parameter" warning is largely unavoidable if you want to use the PREDICATE macro but don't use the PlTermv argument named PL_av in your implementation.

sei-mwd avatar Jun 10 '20 17:06 sei-mwd