1

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://ideone.com/3ggm0E

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'

rparolin
  • 498
  • 2
  • 9
  • declval is required because noexcept is an unevaluated context and we are trying to create an expression which is constructing a T with instances of Args... being passed to T's constructor. – rparolin Jan 28 '15 at 04:49
  • Is potentially an limitation of MSVC partial implementation of expressions FINAE? – rparolin Jan 29 '15 at 07:02
  • MSVC is the problem compiler in this instance. – rparolin Jan 29 '15 at 15:46

0 Answers0