1// Copyright (C) 2018 Tobias Loew
2// Use, modification and distribution is subject to the Boost Software
3// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
4
5#include <boost/config.hpp>
6#include <boost/config/pragma_message.hpp>
7
8#if defined(BOOST_NO_CXX11_LAMBDAS)
9
10BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_LAMBDAS")
11int main() {}
12
13#elif defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
14
15BOOST_PRAGMA_MESSAGE("Skipping test due to BOOST_NO_CXX11_AUTO_DECLARATIONS")
16int main() {}
17
18#else
19
20#include <boost/typeof/typeof.hpp>
21#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
22
23namespace detail {
24 template<class T> inline T& deref(T& r) {
25 return r;
26 }
27 template<class T>
28 struct wrapper {
29 typedef T type;
30 };
31
32 template<class T> wrapper<T> wrap(T&);
33};
34
35BOOST_TYPEOF_REGISTER_TEMPLATE(::detail::wrapper, 1)
36
37void test_typeof_in_lambda() {
38 // 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
39 // the error was due to a change of include in boost/typeof/typeof.hpp (<boost/typeof/decltype.hpp> instead of <boost/typeof/native.hpp>)
40 // This test is an more or less minimal extract from the BOOST_SCOPE_EXIT macro expansions
41
42 // worked also with VS 2015 in version 1.65/1.66
43 int n;
44 typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(n))) n_type_wrapped;
45 typedef n_type_wrapped::type n_type;
46
47 int test;
48
49 auto check_property = [&n,&test]() {
50 // internal compiler error with VS 2015 in version 1.65/1.66
51 // minimal extract from
52 //BOOST_SCOPE_EXIT(test) {
53 // test = 42;
54 //}BOOST_SCOPE_EXIT_END
55
56 // this compiles always (as long as the one before outside the lambda has the same name)
57 typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(n))) n_type_wrapped;
58 typedef n_type_wrapped::type n_type;
59
60 // this fails with internal compiler error with VS 2015 in version 1.65/1.66
61 typedef BOOST_TYPEOF(::detail::wrap(::detail::deref(test))) test_type_wrapped;
62 typedef test_type_wrapped::type test_type;
63
64 };
65
66}
67
68int main() {
69 test_typeof_in_lambda();
70
71 return 0;
72}
73
74#endif
75

source code of boost/libs/typeof/test/msvc_typeof_in_lambda.cpp