if constexpr, C++17

Started by
6 comments, last by Noxil 6 years, 2 months ago

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 :) 

 

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?

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...

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

~Malium

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.

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... :(

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.

This topic is closed to new replies.

Advertisement