Jump to content
  • Advertisement

Recommended Posts

Hey

So i have been tinkering alot with the features of C++17 and i think there are some really nice things that have been added.
But i ran into a problem.

template< class T >
void test() {
	if constexpr( std::is_void_v<T> ) {
		T * t;
	} else {
		T t;
	}
}

int main() {
    test< void >();
	return 0; 
}

Here i expect the compiler to tell me everything is ok and simply skip the else branch.
Since i never call the function "test" with something that isnt a void.
I assume i would only reach the point "T *t".

But thats not the case, im using the very latest version of Visual Studio, 15.5.5.
I have in my project enabled the C++17 language standard and also enabled the conformance mode (/permissive-)
Yet Visual Studio is telling me "illegal use of type 'void'" which of course is correct if i ever where to reach that branch.

Am i just not understanding how its supposed to work?
Any help would be greatly appreciated :) 

 

Share this post


Link to post
Share on other sites
Advertisement

Running that code on the command-line (cl /std:c++latest test.cpp) and with the necessary type_traits include works perfectly fine.

Are you sure there's not some other error that's causing the branch to fail to compile?

Share this post


Link to post
Share on other sites

I dont see any other errors and the code i posted is the minimum i can boil it down to.
Im sure there is something, since im clearly getting the problem, but i just cant see what it could be :(

I enabled someform of more verbose build log and i see this as my build line.

cl /c /ZI /W3 /WX- /diagnostics:classic /sdl /Od /D _DEBUG /D _WINDOWS /D PMPLATFORM_WINDOWS /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /std:c++17 /Fo"x64\Debug\\" /Fd"x64\Debug\vc141.pdb" /Gd /TP /errorReport:prompt Src\Main.cpp

Kinda heavy i think but its the default basically with C++17 enabled.

edit: the command line there is from a windows project, i copied from the wrong project, but it dident work there either...

Edited by Noxil
Clarification on command line

Share this post


Link to post
Share on other sites

Try turning off SDL checks, and solve the warnings that can be raised up by this change 

Edited by malium

Share this post


Link to post
Share on other sites

I tried that, and also i have tried to set the language to latest instead of C++17 to really ensure that the features are enabled at its fullest, but it dosnt seem to work.

Share this post


Link to post
Share on other sites

Okey so im at work right now, created a small test project and everything works fine.
So i assume there is something wrong in my environment... :(

Share this post


Link to post
Share on other sites

As a final note, i ran "Repair" from the Visual Studio installer.
Now everything seems to work. So there was indeed something fishy with my environment.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!