Opened 5 years ago

Last modified 5 years ago

#13076 new Bugs

Compilation error on MSVC2015+ on base_from_member used in a class with __declspec(dllexport)

Reported by: mwu <mwu-tow@…> Owned by: No-Maintainer
Milestone: To Be Determined Component: utility
Version: Boost 1.64.0 Severity: Problem
Keywords: Cc:

Description

Consider the following code:

//#define BOOST_NO_CXX11_VARIADIC_TEMPLATES

#include <boost/utility/base_from_member.hpp>

class __declspec(dllexport) Foo : public boost::base_from_member<int>
{
public:
};

It fails to compile with the following error:

example.cpp
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(135): error C2061: syntax error: identifier 'T'
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(135): note: This diagnostic occurred in the compiler generated function 'boost::base_from_member<int,0>::base_from_member(T &&...) noexcept(<expr>)'
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(136): error C2056: illegal expression
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(136): note: This diagnostic occurred in the compiler generated function 'boost::base_from_member<int,0>::base_from_member(T &&...) noexcept(<expr>)'
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(135): error C2660: 'operator new': function does not take 2 arguments
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(135): note: while compiling class template member function 'boost::base_from_member<int,0>::base_from_member<,void>(void) noexcept(<expr>)'
/opt/compiler-explorer/libs/boost_1_64_0\boost/utility/base_from_member.hpp(135): error C2056: illegal expression
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25017 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.
Compiler exited with result code 2

See https://godbolt.org/g/CqFg8t

If I add the BOOST_NO_CXX11_VARIADIC_TEMPLATES define, the issue goes away. The issue affects both MSVC 2015 and MSVC 2017.

Even if the underlying cause is the compiler error (to be checked), the issue should at least be prevented by proper compiler version detection.

This affects other boost libraries relying on base_from_member, like Boost.Iostreams.

Change History (1)

comment:1 by mwu <mwu-tow@…>, 5 years ago

I reported the bug to Microsoft. They fixed it and fix will likely be available in a future update to VS 2017 C++ toolset.

For the meantime, they kindly provided a few possible workarounds to this issue: https://developercommunity.visualstudio.com/content/problem/69009/compilation-error-on-msvc2015-on-boostbase-from-me.html?childToView=74166#comment-74166

Note: See TracTickets for help on using tickets.