Home My Page Projects cado-nfs
Summary Activity Forums Tracker Lists Tasks Docs News SCM Files

[#21397] shared_ptr should not be imported from libc++ with no guarantee we're c++11.

Date:
2017-07-19 08:43
Priority:
3
State:
Open
Submitted by:
Emmanuel Thomé (thome)
Assigned to:
Nobody (None)
Hardware:
none
Product:
none
Operating System:
none
Component:
none
Version:
none
Severity:
none
Resolution:
none
URL:
Summary:
shared_ptr should not be imported from libc++ with no guarantee we're c++11.

Detailed description
Here's a compiler excerpt for git version 5d5e05eab, on the following machine:
uname -a:
Darwin macintosh-907.home 15.6.0 Darwin Kernel Version 15.6.0: Tue Apr 11 16:00:51 PDT 2017; root:xnu-3248.60.11.5.3~1/RELEASE_X86_64 x86_64
c++ -v:
Apple LLVM version 8.0.0 (clang-800.0.42.1)

(I don't know whether the version of the libc++ can be defined independently of the two above. If yes, I don't know how I can query it).

sieve/CMakeFiles/las_descent.dir/las-coordinates.cpp.o
In file included from /Users/manu/cado-nfs/sieve/las-fb.cpp:4:
In file included from /Users/manu/cado-nfs/sieve/las-types.hpp:5:
/Users/manu/cado-nfs/sieve/fb.hpp:541:7: error: base class 'NonCopyable' has
private copy constructor
class fb_factorbase: public fb_interface, private NonCopyable {
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/u
sr/bin/../include/c++/v1/memory:4503:26: note: in instantiation of function
template specialization 'std::__1::__shared_ptr_emplace<fb_factorbase,
std::__1::allocator<fb_factorbase> >::__shared_ptr_emplace<unsigned int
const[4], const unsigned int, bool const[4]>' requested here
::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
^
Message  ↓
Date: 2017-08-05 16:01
Sender: Emmanuel Thomé

The test was testing std::shared_ptr unconditionally, while it should come with provision for the case that we prefer boost::shared_ptr.

Commit 3f23c8d should fix that.

Date: 2017-08-04 23:35
Sender: Emmanuel Thomé

Ok. Indeed, make_shared not a member of std.
Hopefully I'll fix that tomorrow. The test is stupid.
E.

Date: 2017-08-04 23:06
Sender: Greg Childers

The flags used are these:

-- CFLAGS=-std=c99 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 (synthetized)
-- CXXFLAGS=-std=c++98 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 (synthetized)

The output in the CMakeOutput.log is
Run Build Command:make "cmTryCompileExec3831924109/fast"
make[1]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make -f CMakeFiles/cmTryCompileExec3831924109.dir/build.make CMakeFiles/cmTryCompileExec3831924109.dir/build
make[2]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
/home/gregchilders/cado2/cado-nfs/cmake-installed/bin/cmake -E cmake_progress_report /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec3831924109.dir/src.cxx.o
/usr/bin/c++ -std=c++98 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 -msse3 -mssse3 -msse4.1 -mavx -mpclmul -DHAVE_BOOST_SHARED_PTR -o CMakeFiles/cmTryCompileExec3831924109.dir/src.cxx.o -c /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx
Linking CXX executable cmTryCompileExec3831924109
/home/gregchilders/cado2/cado-nfs/cmake-installed/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3831924109.dir/link.txt --verbose=1
/usr/bin/c++ -std=c++98 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 -msse3 -mssse3 -msse4.1 -mavx -mpclmul -DHAVE_BOOST_SHARED_PTR CMakeFiles/cmTryCompileExec3831924109.dir/src.cxx.o -o cmTryCompileExec3831924109 -rdynamic
make[2]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make[1]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'

Source file was:

#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
namespace std {
using boost::shared_ptr;
using boost::make_shared;
}
struct foo {
std::shared_ptr<int> a;
};
int main()
{
foo f;
f.a = std::make_shared<int>();
return 0;
}

And from CMakeError.log:
Performing C++ SOURCE FILE Test HAVE_STD_SHARED_PTR failed with the following output:
Change Dir: /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp

Run Build Command:make "cmTryCompileExec3776094892/fast"
make[1]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make -f CMakeFiles/cmTryCompileExec3776094892.dir/build.make CMakeFiles/cmTryCompileExec3776094892.dir/build
make[2]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
/home/gregchilders/cado2/cado-nfs/cmake-installed/bin/cmake -E cmake_progress_report /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec3776094892.dir/src.cxx.o
/usr/bin/c++ -std=c++98 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 -msse3 -mssse3 -msse4.1 -mavx -mpclmul -DHAVE_STD_SHARED_PTR -o CMakeFiles/cmTryCompileExec3776094892.dir/src.cxx.o -c /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:4: error: ISO C++ forbids declaration of 'shared_ptr' with no type
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:4: error: invalid use of '::'
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:4: error: expected ';' before '<' token
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx: In function 'int main()':
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:9: error: 'struct foo' has no member named 'a'
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:9: error: 'make_shared' is not a member of 'std'
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:9: error: expected primary-expression before 'int'
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:9: error: expected ';' before 'int'
make[2]: *** [CMakeFiles/cmTryCompileExec3776094892.dir/src.cxx.o] Error 1
make[2]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec3776094892/fast] Error 2
make[1]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'

Source file was:

#include <memory>
struct foo {
std::shared_ptr<int> a;
};
int main()
{
foo f;
f.a = std::make_shared<int>();
return 0;
}

Performing C++ SOURCE FILE Test HAS_NOT_BUG_21397 failed with the following output:
Change Dir: /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp

Run Build Command:make "cmTryCompileExec887518270/fast"
make[1]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make -f CMakeFiles/cmTryCompileExec887518270.dir/build.make CMakeFiles/cmTryCompileExec887518270.dir/build
make[2]: Entering directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
/home/gregchilders/cado2/cado-nfs/cmake-installed/bin/cmake -E cmake_progress_report /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/CMakeFiles 1
Building CXX object CMakeFiles/cmTryCompileExec887518270.dir/src.cxx.o
/usr/bin/c++ -std=c++98 -g -W -Wall -O2 -D__SIZEOF_P_R_VALUES__=8 -msse3 -mssse3 -msse4.1 -mavx -mpclmul -DHAS_NOT_BUG_21397 -o CMakeFiles/cmTryCompileExec887518270.dir/src.cxx.o -c /home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:19: error: expected constructor, destructor, or type conversion before '<' token
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx: In function 'int main()':
/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp/src.cxx:27: error: 'blah' was not declared in this scope
make[2]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make[2]: *** [CMakeFiles/cmTryCompileExec887518270.dir/src.cxx.o] Error 1
make[1]: Leaving directory `/home/gregchilders/cado2/cado-nfs/build/kepler.fullerton.edu/CMakeFiles/CMakeTmp'
make[1]: *** [cmTryCompileExec887518270/fast] Error 2

Source file was:

#include <memory>
class nocopy {
protected:
nocopy() {}
~nocopy() {}
private:
nocopy(const nocopy&);
nocopy& operator=(const nocopy&);
};

class foo: private nocopy {
int val;
public:
foo(int val) : val(val) {}
int value() const { return val; }
};

std::shared_ptr<foo> blah()
{
const int val = 65536;
return std::make_shared<foo>(val);
}

int main()
{
return blah()->value();
}



Date: 2017-08-04 22:39
Sender: Emmanuel Thomé

There are a couple of things at stake here.

Can you post the output of the cmake part (e.g. as with "make cmake") ? I'm curious which gcc flags cmake decided to use.

I wonder whether it's trying to use boost::shared_ptr or std::shared_ptr.

If the latter, then it's really ridiculous because it should have set the flag -std=c++98, no better.

If the former, then looking at config/shared_ptr.cpp it's quite clear that I've botched the check... I should use the same initial snippet as the one I have in sieve/las-types.hpp

Date: 2017-08-04 21:18
Sender: Greg Childers

While trying to compile, I got the error below. Is there a workaround other than upgrading gcc or using another compiler?

CMake Error at config/shared_ptr.cmake:70 (message):
Error, see bug #21397 ; URL is
https://gforge.inria.fr/tracker/index.php?func=detail&aid=21397&group_id=2065&atid=7442
Call Stack (most recent call first):
CMakeLists.txt:292 (include)


-- Configuring incomplete, errors occurred!

I used
-- C compiler: GNU 4.4.7

Date: 2017-08-04 07:19
Sender: Emmanuel Thomé

seems ok.

Date: 2017-07-19 09:21
Sender: Emmanuel Thomé

Commits f8b6723 to ea0e855 should fix that. I'm waiting for the CI bots to come up again, before I close the bug.

Date: 2017-07-19 08:54
Sender: Emmanuel Thomé

It seems that the c++11 flag is not set automatically for this platform.

It's an issue, because we found ourselves happy enough to use shared_ptr from the libc++ namespace. But unless we ask for c++11, we get an implementation which does not offer the same guarantees.

Date: 2017-07-19 08:44
Sender: Emmanuel Thomé

Here's a simpler piece of code with same result:

#include <memory>
class nocopy {
protected:
nocopy() {}
~nocopy() {}
private:
nocopy(const nocopy&);
nocopy& operator=(const nocopy&);
};

class foo: private nocopy {
int val;
public:
foo(int val) : val(val) {}
};

std::shared_ptr<foo> blah()
{
const int val = 65536;
return std::make_shared<foo>(val);
}

Field Old Value Date By
status_idClosed2017-08-04 23:35thome
close_date2017-08-04 07:192017-08-04 23:35thome
ResolutionFixed2017-08-04 23:35thome
status_idOpen2017-08-04 07:19thome
close_dateNone2017-08-04 07:19thome
ResolutionNone2017-08-04 07:19thome
summarysome buggy libc++'s have a shared_ptr which wants a copy ctor2017-07-19 08:54thome