This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++ Patch] PR 34758


Paolo Carlini wrote:

>>   struct S {
>>     S(const S& = f());
>>     static const S& f(int i = 3);
>>   };

> Note that in this case we have, currently:
> 
> t.C:2: error: the default argument for parameter 0 of ‘static const S&
> S::f(int)’ has not yet been parsed

That makes sense to me, modulo the parameter 0 issue.  (The best fix,
would be to refer to "i", rather than "parameter 1" -- but, of course,
"parameter 1" is better than "parameter 0".)

The problem is that when we get to looking at "f()", we haven't yet
parsed the default argument to "f", so we can't work out what "f()"
means.  There's nothing circular here, in a logical sense; if S::f were
declared first, this example would be valid.

This isn't about circularity; it's about ordering.  You parse all of the
declarations of the members first, then you parse their default
arguments, starting with the first member.

Obviously, if the error message doesn't make sense to someone as
knowledgeable about C++ as you, then we should do better.  I just don't
see how the change suggested actually improves the situation.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]