Skip to content

Commit

Permalink
Fix gcc6 compile error. Fix#19
Browse files Browse the repository at this point in the history
Tested on Ubuntu 16.10
  • Loading branch information
mad-de committed Nov 13, 2016
1 parent a5c2bc1 commit 9c4cbe2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion program/base/stann/dpoint.hpp
Expand Up @@ -488,8 +488,9 @@ operator>>(std::istream& is,dpoint<NumType,D> &p)
for (int i=0; i<D; ++i)
if(!(is >> p[i])){
if(!is.eof()){
char errorpoint = is.getloc();
std::cerr << "Error Reading Point:"
<< is << std::endl;
<< errorpoint << std::endl;
exit(1);
}
}
Expand Down

5 comments on commit 9c4cbe2

@nicwib
Copy link

@nicwib nicwib commented on 9c4cbe2 Nov 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears erroneous. istream.getloc() returns a locale object, which cannot be assigned to a char variable.

clang (800.0.38) reports a compilation error on this.
g++-4.9 and g++-6 accept this code; don't know why. (Perhaps because it is a template that is never instantiated?)

@pmoulon
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would recommend to remove the error parsing and just exit?

@nicwib
Copy link

@nicwib nicwib commented on 9c4cbe2 Dec 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I googled a bit:
http://stackoverflow.com/questions/1280885/safely-overloading-stream-operator
http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
https://www.tutorialspoint.com/cplusplus/input_output_operators_overloading.htm

I believe overloaded istream operator >> should not produce any diagnostic upon error, but rather return the istream with appropriate flags set. It is then up to the caller to check the istream and produce diagnostics, if necessary.

In this case, it may be sufficient to just return "is", since it should already have the error flag set.

So perhaps just:
if(!(is >> p[i])){return is;}

@abhvious
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same compile error on Mac OS at this point:

VisualSFM_OS_X_Installer-master/CMVS-PMVS-master/program/base/cmvs/../stann/dpoint.hpp:491:12: error:
no viable conversion from 'std::__1::locale' to 'char'
char errorpoint = is.getloc();
^ ~~~~~~~~~~~
1 error generated.

To fix this, I changed the code to the following from line 491:

if(!is.eof()){
//char errorpoint = is.getloc();
streampos errorpoint = is.tellg();
std::cerr << "Error Reading Point:"
<< errorpoint << std::endl;
exit(1);
}

@Bugaja
Copy link

@Bugaja Bugaja commented on 9c4cbe2 Jul 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Guys,

Having this same issue.

Scanning dependencies of target cmvs_lib
[  1%] Building CXX object base/cmvs/CMakeFiles/cmvs_lib.dir/bundle.cc.o
In file included from /Users/Aaron/CMVS-PMVS-master/program/base/cmvs/bundle.cc:10:
In file included from /Users/Aaron/CMVS-PMVS-master/program/base/cmvs/bundle.h:15:
In file included from /Users/Aaron/CMVS-PMVS-master/program/base/cmvs/../stann/sfcnn.hpp:31:
In file included from /Users/Aaron/CMVS-PMVS-master/program/base/cmvs/../stann/zorder_lt.hpp:20:
/Users/Aaron/CMVS-PMVS-master/program/base/cmvs/../stann/dpoint.hpp:491:12: error: 
      no viable conversion from 'std::__1::locale' to 'char'
                           char errorpoint = is.getloc();
                                ^            ~~~~~~~~~~~
1 error generated.
make[2]: *** [base/cmvs/CMakeFiles/cmvs_lib.dir/bundle.cc.o] Error 1
make[1]: *** [base/cmvs/CMakeFiles/cmvs_lib.dir/all] Error 2
make: *** [all] Error 2
libpba.so failed to build, halting....
Aarons-MacBook-Pro:~ Aaron$ 

I tried to insert as indicated above, but when I save that line into the dpoint.hpp code, then reopen the code in xcode, the saved changes dissapear, and thus I keep getting the same error when I run the .sh

if(!is.eof()){
//char errorpoint = is.getloc();
streampos errorpoint = is.tellg();
std::cerr << "Error Reading Point:"
<< errorpoint << std::endl;
exit(1);
}

Any insight?

Please sign in to comment.