Opened 11 years ago
Closed 10 years ago
#6655 closed Bugs (fixed)
Inclusion of <boost/signals2.hpp> causes valid code to fail to compile with Clang
Reported by: | Owned by: | Frank Mori Hess | |
---|---|---|---|
Milestone: | Boost 1.50.0 | Component: | signals2 |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The following well-formed program does not compile with Clang 3.1 (from trunk):
#include <memory> #include <boost/signals2.hpp> int main() { std::shared_ptr<int> s; }
The error message is:
signals2-bug.cpp:6:26: error: implicit instantiation of undefined template 'std::shared_ptr<int>' std::shared_ptr<int> s; ^ /home/alexander/usr/local/include/boost/signals2/detail/foreign_ptr.hpp:24:30: note: template is declared here template<typename T> class shared_ptr; ^
The header boost/signals2/detail/foreign_ptr.hpp declares two names in the std:: namespace:
#if !defined(BOOST_INTEL_STDCXX0X) namespace std { template<typename T> class shared_ptr; template<typename T> class weak_ptr; } #endif
which is undefined behaviour, according to the Standard 17.6.4.2.1:
The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.
The compilation succeeds, if either the #include of <boost/signals2.hpp> is removed, or the offending lines are commented out.
Please remove the offending lines from the header.
Change History (3)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
comment:3 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Yep. It's not standard-conforming to forward-declare the standard library types (though some standard libraries allow it).
libc++
uses an inline namespace, and so forward declarations in namespacestd
causes compile errors.The solution is to remove the forward declarations and to include
<memory>
.