mardi 27 janvier 2015

VS2015-preview: noexcept expression evaluation fails

I came across this issue trying out code in VS2015 preview. It appears MSVC has an issue evaluating the noexcept expression and causes the error message below. I've worked around the problem by hoisting the noexcept expression into a wrapper struct passing the result to the inherited integral_constant.


I did some searching and I couldn't find anything documenting this as an issue with MSVC. I'm pretty confident this is portable code as libc++ uses this pattern for its type_traits implementations. MSVC implements their version of this type_trait with a compiler intrinsic.


Curious if anyone has any insight before I log an bug with Microsoft.



#include <type_traits>

using namespace std;

template<typename T, typename... Args>
struct is_nothrow_constructible_custom
: public integral_constant<bool, noexcept(T(declval<Args>()...))>
{};

class A
{
public:
A(int) {}
A(short) noexcept {}
};

int main()
{
static_assert(is_nothrow_constructible_custom<A, int>::value == false, "");
static_assert(is_nothrow_constructible_custom<A, short>::value == true, "");
}



GCC 4.9 Works: http://ift.tt/1zvbWyi


MSVC: Compiled with /EHsc /nologo /W4 /c main.cpp main.cpp(7): error C2143: syntax error: missing ')' before '...' main.cpp(8): note: see reference to class template instantiation 'is_nothrow_constructible_custom' being compiled main.cpp(7): error C2947: expecting '>' to terminate template-argument-list, found '>' main.cpp(7): error C2976: 'std::integral_constant': too few template arguments c:\tools_root\cl\inc\xtr1common(34): note: see declaration of 'std::integral_constant' main.cpp(8): error C2955: 'std::integral_constant': use of class template requires template argument list c:\tools_root\cl\inc\xtr1common(34): note: see declaration of 'std::integral_constant'


Aucun commentaire:

Enregistrer un commentaire