vietjtnguyen / argagg

A simple C++11 command line argument parser
MIT License
224 stars 28 forks source link

Cannot use the NOT operator in VS2017 #15

Closed nlappas closed 4 years ago

nlappas commented 6 years ago

Hi,

I am trying to compile with a simple

if(!args["path"]) {
  std::cerr << "Hey I need a path!!!" << std::endl;
  return 0;
}

But I get the following error in Visual Studio 2017

Error C2675 unary '!': 'argagg::option_results' does not define this operator or a conversion to a type acceptable to the predefined operator

any ideas?

(Update: In gcc 5.4 it works properly... This is weird)

vietjtnguyen commented 6 years ago

Hm, I guess Visual Studio doesn't let that degrade to the ! operator on an implicit boolean conversion result? I don't have Visual Studio. A little test with Compiler Explorer and x86-64 MSVC 19 2017 RTW doesn't complain: https://godbolt.org/g/ifxNCb. Can you try the version in the dev-msvc-unary-not-operator branch?

nlappas commented 6 years ago

Wow, thanks for the super fast response!

Yes the new branch works properly

vietjtnguyen commented 6 years ago

Cool. Now I'm not sure if I want to put the explicit unary operator behind an #ifdef on the compiler or not.

Can you provide more detailed version information for your compiler? I tried http://webcompiler.cloudapp.net/ with the following code and it compiled fine without the explicit unary operator.

struct foo {
    int value;
    int threshold;
    operator bool ()
    {
        return value >= threshold;
    }
};

int main()
{
    foo x {1, 2};
    return (!x) ? 0 : -1;
}
nlappas commented 6 years ago

The version is reported as Microsoft (R) C/C++ Optimizing Compiler Version 19.11.25547 for x64

I submitted a bug report to the VS team. Will see how that goes.

https://developercommunity.visualstudio.com/content/problem/159762/implicit-boolean-conversion-fails.html

vietjtnguyen commented 6 years ago

Cool, looks like you got them to add a bug fix:

Leo Zhang [MSFT] · Apr 18 at 01:56 AM 0 Share

Thank you for your feedback! We have fixed the problem in 15.8 Preview 1 which is an upcoming release. Thank you for helping us build a better Visual Studio!