我正在构建的代码,可以在OS X 10.8.5上使用Xcode 4.x,Qt 5.0.1构建良好,但我刚刚升级了Xcode和Qt,在拉入Qt标头时我无法再构建任何东西。
问题是QtSharedPointer 类使用 std::forward,但据我所知,OS X 10.8.5/Xcode 5.0 仍然不支持 std::forward。它没有在随附的标准库中的任何地方定义,因此,当我尝试构建时,出现此错误:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtWidgets.framework/Headers/QAction:1:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtWidgets.framework/Headers/qaction.h:47:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtWidgets.framework/Headers/qwidget.h:49:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtGui.framework/Headers/qpalette.h:47:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtGui.framework/Headers/qbrush.h:53:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtGui.framework/Headers/qpixmap.h:49:
In file included from .../Qt5.1.1/5.1.1/clang_64/lib/QtCore.framework/Headers/qsharedpointer.h:50:
.../Qt5.1.1/5.1.1/clang_64/lib/QtCore.framework/Headers/qsharedpointer_impl.h:411:36: error: no template named 'forward' in namespace 'std'; did you mean 'boost::forward'?
new (result.data()) T(std::forward<Args>(arguments)...);
~~~~~^~~~~~~
boost::forward
/usr/local/include/boost/move/utility.hpp:176:21: note: 'boost::forward' declared here
inline T&& forward(U&& t
^
我确实注意到QtSharedPointer标题顶部的这些行:
#if defined(Q_COMPILER_RVALUE_REFS) && defined(Q_COMPILER_VARIADIC_TEMPLATES)
# include <utility> // for std::forward
#endif
但在下面(第 411 行),它只使用 std::forward,而不检查是否定义了这些宏
// now initialize the data
new (result.data()) T(std::forward<Args>(arguments)...);
这些宏实际上是未定义的,所以,我最初强制包含实用程序,但由于我后来发现 std::forward 不在那里,它没有帮助。
这似乎是一个Qt错误,我打算在那里提交它,但是有人想出解决方法吗?
实际上,我意识到使用 std::forward 的整个方法都由另一个检查Q_COMPILER_RVALUE_REFS的 ifdef 保护。我只是简单地编辑了QtCore.framework/Versions/5/Headers/qcompilerdetection.h,并手动未定义Q_COMPILER_RVALUE_REFS,这让我开始构建。