expected a warning from visual studio


1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

void reprint(char * input)
{
	std::cout << input;
}

int main()
{
	reprint("Hello");
	return 0;
}

Hi all,
I just know about warning: " C++ deprecated conversion from string constant to 'char*' "
But I tested with visual studio 2015, It have not message warning as expected. But when I run on cpp.sh , It have a warning.
How to config for visual.
Thank all.
closed account (E0p9LyTq)
Visual Studio 2017 pops up an error, not a warning.
E0167 argument of type "const char *" is incompatible with parameter of type "char *"
C2664 'void reprint(char *)': cannot convert argument 1 from 'const char [6]' to 'char *'

Visual Studio defaults to a medium warning level. To change the warning level in 2017: Project Properties -> C/C++-> General -> Warning Level.

Default is /W3.

2015 is much more lax on const correctness than 2017. If you have the time, HD space and a good bandwidth I really recommend you replace VS 2105 with 2017. Both are free with the Community edition.

I really recommend not to /Wall, it picks up a lot of warnings from how VS implements the language that you can't fix.
I tried to config with VS2015 as your comment, but It is not.
Thank @FurryGuy,
Thank for your information,
closed account (E0p9LyTq)
Configuring 2015 for a higher warning level won't do anything for this particular issue. It will accept a const char* string to be passed as a char* string.

https://stackoverflow.com/questions/48987994/errors-c2664-and-e0167-stumped

2017 is just better than 2015 if you need to use VS. It is more C++ standard compliant compared to 2015.
Topic archived. No new replies allowed.