Question

As the question suggests, when compiling the code below I want MSVC to notify me that it's using implementation defined behaviour.

void DoStuff_variadic(...)
{}

class SomeClass{
    // 'non-trivial' constructor to make it non-POD
    SomeClass(){};
};

int main()
{
    SomeClass classInstance;
    DoStuff_variadic(classInstance);
}

In Clang++, it would fail with the message:

error: cannot pass object of non-trivial type 'SomeClass' through variadic function; call will abort at runtime [-Wnon-pod-varargs]

I am looking to trigger an error or warning on MSVC11 (without November updates). Is this possible, and if so how would I enable them?

Was it helpful?

Solution

This is not possible in general on MSVC11 without November updates.

When running on /WAll, no warning or error is raised for this problem.

If variadic templates were available as well as variadic functions, you could pass it through an implicit variadic template function. The templated function could then statically check that all types were POD using type traits and static_assert, and then pass the parameters on to the variadic function itself.

MSVC11 does not implement variadic templates. Depending on your usage, it might be viable to implement a set of template functions: one for 0 parameters, one for 1 parameter, one for 2 parameters etc. up until an arbitrary number. Each of these would perform the same function as the variadic templated function described before.

It might be easier to compile on Clang locally, in addition to using MSVC11.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top