[cfe-commits] Note and FixIt for additional case of vexing parse

Richard Smith richard at metafoo.co.uk
Thu Jul 26 15:25:16 PDT 2012


On Thu, Jul 26, 2012 at 3:12 PM, Nikola Smiljanic <popizdeh at gmail.com>wrote:

> > Please move this into an "if (FTI.isAmbiguous)" check. We don't want to
> pay
> > for this when building every function type. Also, if you can factor this
> out
> > to a separate function, that would help avoid disrupting the flow of this
> > function.
>
> In that case I could add a function IsPointerDeclarator (probably
> should name it differently?) to Declarator and call both it and
> IsFunctionDeclarator inside the "if (FTI.isAmbiguous)". The code would
> look something like this:
>
> // avoid other costly checks if possible
> if (FTI.isAmbiguous) {
>     if (other conditions including IsFunctionDeclarator and
> IsPointerDeclarator)
> }
>

I meant, move all the ambiguous direct init / function declaration checking
into a separate function, not just this loop.


> > We should also be checking (RT->isRecordType() || FTI.NumArgs <= 1) here.
>
> I still don't get this part, but it might be because we don't
> understand each other about the "return type a reference" stuff. See
> the next part.
>
> > I don't follow. If the return type is a reference, then it's not a class
> type.
>
> I'm not very good at standardese so my terminology might be off. When
> I say a reference, I mean something like this:
>
> int &foo();
> MyClass &bar();
>
> Return type is a reference to some other type that might be a class
> type (class MyClass {};) or a built-in type. I just don't see how
> return type being a class type changes anything?


For the cases where the return type is a reference, I completely agree with
you -- there must be exactly one argument.

In these cases, the return type isn't a class type, it's a reference type.
The class type case looks like this:

MyClass bar(x, y);

The point is, if we're not in this case, there can be at most one argument,
because you can only have multiple arguments in a direct-initialization if
you're calling a constructor.

So the rules are:
 - if the return type is not a class type, there can be at most one
parameter
 - if the return type is a reference type, there must be exactly one
parameter

I hope you understand what it is that I don't understand. Sorry for
> being such a pain, and thanks for all the help!
>

I hope the above helps to clarify.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120726/633aa993/attachment.html>


More information about the cfe-commits mailing list