-1

The reason that I ask this question is this link below: Why can this function return a C++ int reference?

It seems that the compiler is bad at reporting mistakes such as: return a value from a function.

So I want to activate them in Visual Studio 2019, but it did not work after I set it (restart IDE) like below:

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Wayne JP
  • 1
  • 2
  • 1
    The combination of flags you want is `/W4 /permissive-` see live: https://godbolt.org/z/T8BufA . Note that `/Wall` will produce too many messages include ones from the standard headers. I currently don't have access to MSVS confirm where in the GUI the settings are. – Richard Critten Nov 17 '19 at 12:17
  • 1
    Returning reference to temporary is reported even with `/W1`, it is not clear how you managed not to get it. – user7860670 Nov 17 '19 at 12:22

1 Answers1

0

I suggest you could try to use the following method to enable warnings that are off by default:

1,#pragma warning(default : warning_number ) The specified warning (warning_number) is enabled at its default level. Documentation for the warning contains the default level of the warning.

2,#pragma warning( warning_level : warning_number ) The specified warning (warning_number) is enabled at the specified level (warning_level).

3,/Wall /Wall enables all warnings that are off by default. If you use this option, you can turn off individual warnings by using the /wd option.

4,/wLnnnn This option enables warning nnnn at level L.

For more details anbout warning level, I suggest you could refer to the link:https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=vs-2019

Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20