If the sole distinction between two declarations is that one has a
__restrict qualifier then we should not consider it to be an overload.
Instead, we will consider it as an incompatible redeclaration which is
similar to how MSVC, ICC and GCC would handle it.
This fixes PR17786.
N.B. We must not mangle in __restrict into method qualifiers becase we
don't allow overloading between such declarations anymore. To do
otherwise would be a violation of the Itanium ABI.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193964
91177308-0d34-0410-b5e6-
96231b3b80d8
Out << 'N';
if (const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(ND)) {
- mangleQualifiers(Qualifiers::fromCVRMask(Method->getTypeQualifiers()));
+ Qualifiers MethodQuals =
+ Qualifiers::fromCVRMask(Method->getTypeQualifiers());
+ // We do not consider restrict a distinguishing attribute for overloading
+ // purposes so we must not mangle it.
+ MethodQuals.removeRestrict();
+ mangleQualifiers(MethodQuals);
mangleRefQualifier(Method->getRefQualifier());
}
// function yet (because we haven't yet resolved whether this is a static
// or non-static member function). Add it now, on the assumption that this
// is a redeclaration of OldMethod.
+ unsigned OldQuals = OldMethod->getTypeQualifiers();
unsigned NewQuals = NewMethod->getTypeQualifiers();
if (!getLangOpts().CPlusPlus1y && NewMethod->isConstexpr() &&
!isa<CXXConstructorDecl>(NewMethod))
NewQuals |= Qualifiers::Const;
- if (OldMethod->getTypeQualifiers() != NewQuals)
+
+ // We do not allow overloading based off of '__restrict'.
+ OldQuals &= ~Qualifiers::Restrict;
+ NewQuals &= ~Qualifiers::Restrict;
+ if (OldQuals != NewQuals)
return true;
}
void g(zed<&foo::bar>*)
{}
}
+
+namespace test44 {
+ struct foo { void bar() __restrict { }; } obj;
+
+ void f() {
+ obj.bar();
+ }
+ // CHECK-LABEL: define linkonce_odr void @_ZN6test443foo3barEv(%"struct.test44::foo"* %this)
+}
static void g(float); // expected-note {{previous declaration is here}}
static void g(int); // expected-error {{static and non-static member functions with the same parameter types cannot be overloaded}}
static void g(float); // expected-error {{class member cannot be redeclared}}
+
+ void h(); // expected-note {{previous declaration is here}} \
+ expected-note {{previous declaration is here}}
+ void h() __restrict; // expected-error {{class member cannot be redeclared}} \
+ expected-error {{conflicting types for 'h'}}
};
int main() {} // expected-note {{previous definition is here}}