More of N3652: don't add an implicit 'const' to 'constexpr' member functions when checking for overloads in C++1y.
llvm-svn: 184865
This commit is contained in:
parent
c43250338a
commit
e83b1d3e7a
|
@ -1080,7 +1080,8 @@ static bool shouldTryToOverload(Sema &S, FunctionDecl *New, FunctionDecl *Old,
|
|||
// or non-static member function). Add it now, on the assumption that this
|
||||
// is a redeclaration of OldMethod.
|
||||
unsigned NewQuals = NewMethod->getTypeQualifiers();
|
||||
if (NewMethod->isConstexpr() && !isa<CXXConstructorDecl>(NewMethod))
|
||||
if (!S.getLangOpts().CPlusPlus1y && NewMethod->isConstexpr() &&
|
||||
!isa<CXXConstructorDecl>(NewMethod))
|
||||
NewQuals |= Qualifiers::Const;
|
||||
if (OldMethod->getTypeQualifiers() != NewQuals)
|
||||
return true;
|
||||
|
|
|
@ -1670,3 +1670,27 @@ namespace StmtExpr {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
namespace VirtualFromBase {
|
||||
struct S1 {
|
||||
virtual int f() const;
|
||||
};
|
||||
struct S2 {
|
||||
virtual int f();
|
||||
};
|
||||
template <typename T> struct X : T {
|
||||
constexpr X() {}
|
||||
double d = 0.0;
|
||||
constexpr int f() { return sizeof(T); } // expected-warning {{will not be implicitly 'const' in C++1y}}
|
||||
};
|
||||
|
||||
// Virtual f(), not OK.
|
||||
constexpr X<X<S1>> xxs1;
|
||||
constexpr X<S1> *p = const_cast<X<X<S1>>*>(&xxs1);
|
||||
static_assert(p->f() == sizeof(X<S1>), ""); // expected-error {{constant expression}} expected-note {{virtual function call}}
|
||||
|
||||
// Non-virtual f(), OK.
|
||||
constexpr X<X<S2>> xxs2;
|
||||
constexpr X<S2> *q = const_cast<X<X<S2>>*>(&xxs2);
|
||||
static_assert(q->f() == sizeof(S2), "");
|
||||
}
|
||||
|
|
|
@ -790,3 +790,27 @@ namespace StmtExpr {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
namespace VirtualFromBase {
|
||||
struct S1 {
|
||||
virtual int f() const;
|
||||
};
|
||||
struct S2 {
|
||||
virtual int f();
|
||||
};
|
||||
template <typename T> struct X : T {
|
||||
constexpr X() {}
|
||||
double d = 0.0;
|
||||
constexpr int f() { return sizeof(T); }
|
||||
};
|
||||
|
||||
// Non-virtual f(), OK.
|
||||
constexpr X<X<S1>> xxs1;
|
||||
constexpr X<S1> *p = const_cast<X<X<S1>>*>(&xxs1);
|
||||
static_assert(p->f() == sizeof(S1), "");
|
||||
|
||||
// Virtual f(), not OK.
|
||||
constexpr X<X<S2>> xxs2;
|
||||
constexpr X<S2> *q = const_cast<X<X<S2>>*>(&xxs2);
|
||||
static_assert(q->f() == sizeof(X<S2>), ""); // expected-error {{constant expression}} expected-note {{virtual function call}}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue