Sema: Enforce C++11 pointer-to-member template arguments should rules

The standard is pretty clear on what it allows inside of template
arguments for non-type template parameters of pointer-to-member.

They must be of the form &qualified-id and cannot come from sources like
constexpr VarDecls or things of that nature.

This fixes PR18192.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196852 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer 2013-12-10 00:40:58 +00:00
parent cdc988f427
commit fe34a2b420
2 changed files with 9 additions and 4 deletions

View File

@ -4584,9 +4584,7 @@ static bool CheckTemplateArgumentPointerToMember(Sema &S,
else if ((DRE = dyn_cast<DeclRefExpr>(Arg))) {
if (ValueDecl *VD = dyn_cast<ValueDecl>(DRE->getDecl())) {
if (VD->getType()->isMemberPointerType()) {
if (isa<NonTypeTemplateParmDecl>(VD) ||
(isa<VarDecl>(VD) &&
S.Context.getCanonicalType(VD->getType()).isConstQualified())) {
if (isa<NonTypeTemplateParmDecl>(VD)) {
if (Arg->isTypeDependent() || Arg->isValueDependent()) {
Converted = TemplateArgument(Arg);
} else {

View File

@ -1,4 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
struct Y {
int x;
};
@ -65,3 +65,10 @@ namespace ValueDepMemberPointer {
}
S<int> s;
}
namespace PR18192 {
struct A { struct { int n; }; };
template<int A::*> struct X {};
constexpr int A::*p = &A::n;
X<p> x; // expected-error{{not a pointer to member constant}}
}