From 080f05ea46271c745f7a748815a64210deb0a880 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 13 Jan 2018 20:46:25 +0200 Subject: [PATCH] Squash-merge branch feature/pull-11 --- include/boost/typeof/typeof.hpp | 3 +- test/msvc_typeof_in_lambda.cpp | 74 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/msvc_typeof_in_lambda.cpp diff --git a/include/boost/typeof/typeof.hpp b/include/boost/typeof/typeof.hpp index 1efa3dc..d2c49fb 100644 --- a/include/boost/typeof/typeof.hpp +++ b/include/boost/typeof/typeof.hpp @@ -14,8 +14,9 @@ #endif #include +#include -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_TYPEOF_EMULATION) +#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) && !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_TYPEOF_EMULATION) # define BOOST_TYPEOF_DECLTYPE # ifndef BOOST_TYPEOF_NATIVE # define BOOST_TYPEOF_NATIVE diff --git a/test/msvc_typeof_in_lambda.cpp b/test/msvc_typeof_in_lambda.cpp new file mode 100644 index 0000000..ae388f1 --- /dev/null +++ b/test/msvc_typeof_in_lambda.cpp @@ -0,0 +1,74 @@ +// Copyright (C) 2018 Tobias Loew +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +#if defined(BOOST_NO_CXX11_LAMBDAS) + +BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_LAMBDAS") +int main() {} + +#elif defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) + +BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_AUTO_DECLARATIONS") +int main() {} + +#else + +#include +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +namespace detail { + template inline T& deref(T& r) { + return r; + } + template + struct wrapper { + typedef T type; + }; + + template wrapper wrap(T&); +}; + +BOOST_TYPEOF_REGISTER_TEMPLATE(::detail::wrapper, 1) + +void test_typeof_in_lambda() { + // Visual Studio 2015 (BOOST_MSVC == 1900) had an internal compiler error with Boost 1.65 and 1.66 when using BOOST_SCOPE_EXIT inside a lambda + // the error was due to a change of include in boost/typeof/typeof.hpp ( instead of ) + // This test is an more or less minimal extract from the BOOST_SCOPE_EXIT macro expansions + + // worked also with VS 2015 in version 1.65/1.66 + int n; + typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(n))) n_type_wrapped; + typedef n_type_wrapped::type n_type; + + int test; + + auto check_property = [&n,&test]() { + // internal compiler error with VS 2015 in version 1.65/1.66 + // minimal extract from + //BOOST_SCOPE_EXIT(test) { + // test = 42; + //}BOOST_SCOPE_EXIT_END + + // this compiles always (as long as the one before outside the lambda has the same name) + typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(n))) n_type_wrapped; + typedef n_type_wrapped::type n_type; + + // this fails with internal compiler error with VS 2015 in version 1.65/1.66 + typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(test))) test_type_wrapped; + typedef test_type_wrapped::type test_type; + + }; + +} + +int main() { + test_typeof_in_lambda(); + + return 0; +} + +#endif