On Wed, May 12, 2021 at 10:37:50AM -0400, Jason Merrill wrote:
> On 5/11/21 10:45 PM, Marek Polacek wrote:
> > This patch implements [dcl.attr.grammar]/5: "If an attribute-specifier-seq
> > appertains to a friend declaration ([class.friend]), that declaration shall
> > be a definition."
> > 
> > This restriction only applies to C++11-style attributes.  There are
> > various forms of friend declarations, we have friend templates, C++11
> > extended friend declarations, and so on.  In some cases we already
> > ignore the attribute and warn that it was ignored.  But certain cases
> > weren't diagnosed, and with this patch we'll give a hard error.  I tried
> > hard not to emit both a warning and error and I think it worked out.
> 
> Hmm, why error in this case rather than the usual warning?

I thought such usage (C++11 attribute on a friend) is so rare (no occurrences
in the testsuite) that it'd be better to go straight for an error.  Though
I do see the argument that generally we ignore unknown/misplaced attributes.
clang gives errors, FWIW.
 
> Also, we should warn about similarly useless GNU attributes on friends.

That's unfortunately more complicated: we should(?) accept

#define vector __attribute__((vector_size(16)))
class A {
  friend vector float f();
};

vector float vf;
vector float
f ()
{
  return vf;
}

So I limited the patch for [[]] only.

Marek

Reply via email to