Search code examples
c++visual-studio-2017c++17nodiscard

Trying out [[nodiscard]] with no success


I am trying to test a little C++17. I am trying to do:

[[nodiscard]] int get_value1()
{
    return 42;
}

inline void start()
{
    // Should generate warning
    get_value1();
}

However, it does not. I am using Visual studio 2017. Warning level set to Level4(\W4). I have set C++ Language Standard to ISO C++ Latest Draft Standard (/std:c++latest).

But it does not generate the warning that I want. Why is that? Also, a little side question: That tab to select the language standard only appears in Debug configuration and not Release. Why is that? Release complains on the nodiscard, Would that mean that Release is in C++14?

edit: naturally I meant warning in the second section. Corrected. :)


Solution

  • Actually [[nodiscard]] is supported only since VS 2017.3 and it should give you a warning, not an error. And as I understand specification assumes that compiler may warn you. And may not.