https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69843

            Bug ID: 69843
           Summary: C++: Inconsistent treatment of may_alias attribute and
                    forward declarations
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---

This is a bit inconsistent.  I would expect an error on the definition because
it is inconsistent with the forward declaration.  may_alias should not make a
difference here because no access is possible through the incomplete struct.

Bug 61834 may be related.

struct sockaddr;
struct sockaddr *f();

struct __attribute__((may_alias)) sockaddr {};
struct sockaddr *f()
{
  return nullptr;
}

results in:

t.cc: In function ‘sockaddr* f()’:
t.cc:5:18: error: ambiguating new declaration of ‘sockaddr* f()’
 struct sockaddr *f()
                  ^

t.cc:2:18: note: old declaration ‘sockaddr* f()’
 struct sockaddr *f();
                  ^

Reply via email to