coin-or / OS

Optimization Services
Other
1 stars 4 forks source link

Error: taking address of rvalue [-fpermissive] #69

Closed sagitter closed 2 years ago

sagitter commented 3 years ago

Hi all.

unitTest.cpp is not compiled in Fedora 35 (coin-or-OS-2.10.2 and GCC-11.1.1) with following error:

cd test; make test
make[1]: Entering directory '/builddir/build/BUILD/OS-2.10.2/test'
g++ -DHAVE_CONFIG_H -I. -I`echo .` -I../src  -I`echo ./../src` -I`echo ./../src/OSAgent` -I`echo ./../src/OSParsers` -I`echo ./../src/OSUtils` -I`echo ./../src/OSSolverInterfaces` -I`echo ./../src/OSModelInterfaces` -I`echo ./../src/OSCommonInterfaces` -I/usr/include/cppad  -I/usr/include/asl -I/usr/include/coin  -I/usr/include/coin -I/usr/include/cppad  -I/usr/include/coin -I/usr/include/cppad  -I/usr/include/coin  -I/usr/include/coin  -I/usr/include/coin  -I/usr/include/coin  -I/usr/include/coin  -I/usr/include/coin  -I/usr/include/coin -I/usr/include/cppad  -I/usr/include/coin    -I`echo /usr/include/csdp` -DNOSHORTS    -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -I/usr/include/asl -std=gnu++14  -DOS_BUILD -fopenmp -c -o unitTest.o unitTest.cpp
In file included from unitTest.cpp:144:
./../src/OSSolverInterfaces/OSCoinSolver.h:56:27: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   56 |     virtual void  solve() throw(ErrorClass);
      |                           ^~~~~
./../src/OSSolverInterfaces/OSCoinSolver.h:62:41: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   62 |     virtual void  buildSolverInstance() throw(ErrorClass);
      |                                         ^~~~~
./../src/OSSolverInterfaces/OSCoinSolver.h:68:38: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   68 |     virtual void  setSolverOptions() throw(ErrorClass);
      |                                      ^~~~~
In file included from ./../src/OSSolverInterfaces/OSCouenneSolver.h:20,
                 from unitTest.cpp:178:
./../src/OSSolverInterfaces/OSBonminSolver.h:251:27: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
  251 |     virtual void  solve() throw (ErrorClass) ;
      |                           ^~~~~
./../src/OSSolverInterfaces/OSBonminSolver.h:257:41: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
  257 |     virtual void  buildSolverInstance() throw(ErrorClass);
      |                                         ^~~~~
./../src/OSSolverInterfaces/OSBonminSolver.h:263:38: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
  263 |     virtual void  setSolverOptions() throw(ErrorClass);
      |                                      ^~~~~
In file included from unitTest.cpp:178:
./../src/OSSolverInterfaces/OSCouenneSolver.h:79:27: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   79 |     virtual void  solve() throw (ErrorClass) ;
      |                           ^~~~~
./../src/OSSolverInterfaces/OSCouenneSolver.h:85:41: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   85 |     virtual void  buildSolverInstance() throw(ErrorClass);
      |                                         ^~~~~
./../src/OSSolverInterfaces/OSCouenneSolver.h:91:38: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   91 |     virtual void  setSolverOptions() throw(ErrorClass);
      |                                      ^~~~~
In file included from unitTest.cpp:199:
./../src/OSSolverInterfaces/OSCsdpSolver.h:94:27: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
   94 |     virtual void  solve() throw (ErrorClass) ;
      |                           ^~~~~
./../src/OSSolverInterfaces/OSCsdpSolver.h:100:41: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
  100 |     virtual void  buildSolverInstance() throw(ErrorClass);
      |                                         ^~~~~
./../src/OSSolverInterfaces/OSCsdpSolver.h:106:38: warning: dynamic exception specifications are deprecated in C++11 [-Wdeprecated]
  106 |     virtual void  setSolverOptions() throw(ErrorClass);
      |                                      ^~~~~
unitTest.cpp: In function 'int main(int, char**)':
unitTest.cpp:9784:68: error: taking address of rvalue [-fpermissive]
 9784 |                     static_cast<ostringstream*>( &(ostringstream() << (2*j - 2)) )->str()))
      |                                                   ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
make[1]: Leaving directory '/builddir/build/BUILD/OS-2.10.2/test'
make[1]: *** [Makefile:512: unitTest.o] Error 1
tkralphs commented 3 years ago

This looks pretty easy to fix. A PR would be most welcome! Looks like the same issue is present in master so it probably makes sense to do the PR against the master branch.

svigerske commented 3 years ago

I fixed this up in stable/2.10 for now. Can you try whether that is sufficient for you? The OS developers haven't been active for 2 years, so not sure how likely it is that someone would try to fix any failing tests.

I can cherry-pick to master when we are done here.

sagitter commented 2 years ago

Sorry for my late reply.

Change in https://github.com/coin-or/OS/commit/2a7dd973a031a48d5de832f43b5f5fec5cf17dca is applied but Cspd solver test is failing:

TEST 15: CSDP solver on SDPA_ex.osil
create a new Csdp Solver for OSiL string solution
call the Csdp Solver
CSDP 6.2.0
Iter:  0 Ap: 0.00e+00 Pobj:  3.0434379e+02 Ad: 0.00e+00 Dobj:  0.0000000e+00 
Iter:  1 Ap: 8.36e-01 Pobj:  3.6123735e+01 Ad: 1.00e+00 Dobj:  3.6192774e+01 
Iter:  2 Ap: 9.91e-01 Pobj:  1.7890107e+00 Ad: 1.00e+00 Dobj:  3.4979250e+01 
Iter:  3 Ap: 1.00e+00 Pobj:  1.5056174e+00 Ad: 1.00e+00 Dobj:  8.0480383e+00 
Iter:  4 Ap: 1.00e+00 Pobj:  1.8308676e+00 Ad: 1.00e+00 Dobj:  3.3375932e+00 
Iter:  5 Ap: 9.97e-01 Pobj:  2.6201334e+00 Ad: 1.00e+00 Dobj:  3.0665240e+00 
Iter:  6 Ap: 1.00e+00 Pobj:  2.7034721e+00 Ad: 1.00e+00 Dobj:  2.7846974e+00 
Iter:  7 Ap: 1.00e+00 Pobj:  2.7475837e+00 Ad: 1.00e+00 Dobj:  2.7511007e+00 
Iter:  8 Ap: 1.00e+00 Pobj:  2.7499233e+00 Ad: 9.98e-01 Dobj:  2.7500315e+00 
Iter:  9 Ap: 1.00e+00 Pobj:  2.7499976e+00 Ad: 9.98e-01 Dobj:  2.7499990e+00 
Iter: 10 Ap: 1.00e+00 Pobj:  2.7499999e+00 Ad: 9.99e-01 Dobj:  2.7500000e+00 
Iter: 11 Ap: 9.70e-01 Pobj:  2.7500000e+00 Ad: 9.70e-01 Dobj:  2.7500000e+00 
Success: SDP solved
Primal objective value: 2.7500000e+00 
Dual objective value: 2.7500000e+00 
Relative primal infeasibility: 9.70e-17 
Relative dual infeasibility: 7.62e-10 
Real Relative Gap: 2.02e-10 
XZ Relative Gap: 4.80e-10 
DIMACS error measures: 1.05e-16 0.00e+00 2.24e-09 0.00e+00 2.02e-10 4.80e-10
Csdp solver solution for SDPA_ex checks.
now test matrix extensions to OSrL
Read OSrL string
Write OSrL string
THE UNIT TEST PASSED THE FOLLOWING:
TEST 1: Reading files successfully
TEST 2: Passed lossless IO test
TEST 3: Successful test of nonlinear operators using file testOperators.osil
TEST 4: Successful test of AD gradient and Hessian calculations
TEST 5: Solved problem parincLinearByRow.osil with Clp
TEST 6: Warmstarts for problem parincLinear.osil with Clp
TEST 7: Solved problem p0033.osil with Cbc
TEST 8: Solved problem p0033.osil with SYMPHONY
TEST 9: Solved problem parincLinear.osil with DyLP
TEST 10: Solved problem volumeTest.osil with Vol
TEST 11: Solved problem p0033.osil with GLPK
TEST 12: Solved problem avion2.osil with Ipopt
TEST 13: Solved problem bonminEx1.osil with Bonmin
TEST 14: Solved problem bonminEx1.osil with Couenne
UNFORTUNATELY, YOU FAILED ON THE FOLLOWING:
Test 15: Unit Test Failed Testing the Csdp Solver:
OSrL reader/writer loses information in matrix extensions
Conclusion: FAILURE
make[1]: *** [Makefile:707: test] Error 1
svigerske commented 2 years ago

That seems to be a bug with the IsEqual() implementation of OSResult and all classes used by it.

There is a lot of code like

           if (!this->generalStatus->IsEqual(that->generalStatus))
                return false;

[...]

bool GeneralStatus::IsEqual(GeneralStatus *that)
{
    std::ostringstream outStr;

#ifndef NDEBUG
    osoutput->OSPrint(ENUM_OUTPUT_AREA_OSResult, ENUM_OUTPUT_LEVEL_trace, "Start comparing in GeneralStatus");
#endif
    if (this == NULL)
    {
        if (that == NULL)
            return true;
[...]

all over the place.

However, the check this == NULL does not work reliably if this is NULL. There should be a check for this->generalStatus == NULL in the first code snippet. I guess this is due to compiler optimizations, so I put some #ifdef around the test that should disable it in a non-debug build of OS.

svigerske commented 2 years ago

I created a follow-up issue for the last thing.

sagitter commented 2 years ago

Hi Stefan.

Thank for your help. The test error in https://github.com/coin-or/OS/issues/69#issuecomment-891741254 is still there also after change from https://github.com/coin-or/OS/commit/588350e0c04a77599292064960f8e68869935f2c

svigerske commented 2 years ago

Hmm, ok. I took it out completely now.