Skip to content

Fix build error with g++ 6.3 (Debian Stretch) - #357

Merged
mpictor merged 1 commit into
stepcode:masterfrom
jepler:nullptr-bool
Aug 19, 2017
Merged

Fix build error with g++ 6.3 (Debian Stretch)#357
mpictor merged 1 commit into
stepcode:masterfrom
jepler:nullptr-bool

Conversation

@jepler

@jepler jepler commented Aug 12, 2017

Copy link
Copy Markdown
Contributor

On this platform, TEST_NULLPTR fails, even though nullptr and
nullptr_t are supported:

/home/jepler/src/stepcode/build/CMakeFiles/CMakeTmp/src.cxx:4:23:
    error: converting to 'bool' from 'std::nullptr_t'
    requires direct-initialization [-fpermissive]
 int main() {return !!f();}
                      ~^~

Subsequent to this failure, the workaround definitions in sc_nullptr.h
prevent standard C++ headers (which must refer to real nullptr) from
compiling.

The failure occurs because the C++ standard apparently does not state
that operator! may be used on nullptr. Despite this, some compilers
have historically allowed it. g++ 6.3's behavior appears to be aligned
with the standard.

@brlcad

brlcad commented Aug 12, 2017

Copy link
Copy Markdown
Member

The problem with this patch is the compiler can ignore f() if it's unused. That'd mean it trades your false negative error case to a false positive error for others. Can you try a different approach? I'd expect a simple cast to work just fine (e.g., return (int)f();).

@mpictor

mpictor commented Aug 13, 2017

Copy link
Copy Markdown
Member

travis-ci failure:

...
[ 28%] Building C object src/express/CMakeFiles/express.dir/info.c.o
Linking CXX shared library ../../lib/libexpress.so
CMake Error: cmake_symlink_library: System Error: File exists
...

Not sure what happened, but appears unrelated to the change. Been a looong time since I did much of anything with stepcode.

As for appveyor, I'm not sure it ever worked :/

@jepler

jepler commented Aug 14, 2017

Copy link
Copy Markdown
Contributor Author

I have updated this pull request to address @brlcad's suggestion.

On this platform, TEST_NULLPTR fails, even though nullptr and
nullptr_t are supported:

/home/jepler/src/stepcode/build/CMakeFiles/CMakeTmp/src.cxx:4:23:
    error: converting to 'bool' from 'std::nullptr_t'
    requires direct-initialization [-fpermissive]
 int main() {return !!f();}
                      ~^~

Subsequent to this failure, the workaround definitions in sc_nullptr.h
prevent standard C++ headers (which must refer to real nullptr) to fail.

The failure occurs because the C++ standard apparently does not state
that operator! may be used on nullptr.  Despite this, some compilers
have historically allowed it.  g++ 6.3's behavior appears to be aligned
with the standard.

As requested by @brlcad, ensure that the function 'f' is used from main,
to avoid a clever (but not nullptr-supporting) compiler from somehow
skipping 'f' altogether, creating a false positive for nullptr support.
@mpictor
mpictor merged commit beb2a59 into stepcode:master Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants