Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 "Simplify Instance" breaks with vexing parse rule

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Myria Posted - Jan 16 2018 : 4:14:44 PM
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
3   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Jan 17 2018 : 07:20:36 AM
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.
Myria Posted - Jan 16 2018 : 6:20:23 PM
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 =^-^=
feline Posted - Jan 16 2018 : 4:40:43 PM
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

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000