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

            Bug ID: 72865
           Summary: Adding __may_alias__ attribute triggers a compilation
                    error
           Product: gcc
           Version: 5.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: root at zta dot lk
  Target Milestone: ---

The following (correct) code triggers a compilation error when compiled with
gcc. It does compiles under clang.
Removing __attribute__((__may_alias__)) clause fixes the problem.

$ cat sf.cpp
template <class T>
class rv: public T
{
   rv();
   ~rv() throw();
   rv(rv const&);
   void operator=(rv const&);
} __attribute__((__may_alias__));

class A
{
  A(A &);
  A& operator=(A &);
public:
  explicit A(rv<A>& safetyCamera);
  A& operator=(rv<A>& safetyCamera);
  operator const rv<A>&() const { return *static_cast<const rv<A>*>(this); }
};

A::A(rv<A>&) {}
A& A::operator=(rv<A>&) { return *this; }



The error message
=================

$ g++ -c sf.cpp
sf.cpp:20:1: error: prototype for ‘A::A(rv<A>&)’ does not match any in class
‘A’
 A::A(rv<A>&) {}
 ^
sf.cpp:15:12: error: candidates are: A::A(rv<A>&)
   explicit A(rv<A>& safetyCamera);
            ^
sf.cpp:12:3: error:                 A::A(A&)
   A(A &);
   ^
sf.cpp:21:4: error: prototype for ‘A& A::operator=(rv<A>&)’ does not match any
in class ‘A’
 A& A::operator=(rv<A>&) { return *this; }
    ^
sf.cpp:16:6: error: candidates are: A& A::operator=(rv<A>&)
   A& operator=(rv<A>& safetyCamera);
      ^
sf.cpp:13:6: error:                 A& A::operator=(A&)
   A& operator=(A &);
      ^

Reply via email to