Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 "Simplify Instance" breaks with vexing parse rule
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Myria
New Member

USA
9 Posts

Posted - Jan 16 2018 :  4:14:44 PM  Show Profile  Reply with Quote
The new "Simplify Instance Declaration" feature doesn't account for the C++ "most vexing parse" rule. This example is contrived, but shows the problem:

struct S
{
    S(int i) : m_i(i) {}
    operator int() const { return m_i; }
    int m_i;
};

int f(int x)
{
    auto i = int(S(x));
    return i;
}


If "Simplify Instance Declaration" is used on the declaration of "i", then VAX generates the following incorrect code:

int i(S(x));


By C++'s "most vexing parse" rule, this is parsed as a function declaration, not a variable initialization. VAX should generate one of these two lines instead:

int i{S(x)};
int i((S(x)));


The former requires a compiler new enough to understand the brace initialization syntax (VS 2012? 2013?).

Melissa

feline
Whole Tomato Software

United Kingdom
19022 Posts

Posted - Jan 16 2018 :  4:40:43 PM  Show Profile  Reply with Quote
Is the "most vexing parse" rule a real rule? Or does it just feel like this when people start doing strange things with C++? I don't recognise the rule name, but I do recognise the feeling.

Out of interest, why use a struct here, not a class? I know a struct has the same features as a class, but normally I never see a struct with member functions.

I am seeing the same problem with your code, and have to think for a few moments to follow what you are doing here:

case=113819

thank you for the "clear" example

zen is the art of being at one with the two'ness
Go to Top of Page

Myria
New Member

USA
9 Posts

Posted - Jan 16 2018 :  6:20:23 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

Is the "most vexing parse" rule a real rule? Or does it just feel like this when people start doing strange things with C++? I don't recognise the rule name, but I do recognise the feeling.


It's just a name that an author gave a particular ambiguity resolution rule in the C++ standard. For whatever reason, the name "most vexing parse rule" has stuck in the C++ community.

https://en.wikipedia.org/wiki/Most_vexing_parse

quote:
Out of interest, why use a struct here, not a class? I know a struct has the same features as a class, but normally I never see a struct with member functions.


I used "struct" because I didn't want to have to type "public:" and "private:" in my example. The actual place I ran into this was on a class, not a struct. It doesn't matter for the purpose of this example =^-^=
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19022 Posts

Posted - Jan 17 2018 :  07:20:36 AM  Show Profile  Reply with Quote
Interesting, I did not know that. Always something new to learn

Good to know that you are using a class when you came across this, I asked partly because occasionally VA can be tripped up by using a struct as if it was a class. It's something of an edge case normally.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000