From fabf95d0667b5dcc9da3d5537f1d3ca20b2914b5 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 30 Apr 2010 21:46:38 +0000 Subject: After substituting a template argument for a non-type template parameter with pointer-to-member type, we may have to perform a qualification conversion, since the pointee type of the parameter might be more qualified than the pointee type of the argument we form from the declaration. Fixes PR6986. llvm-svn: 102777 --- clang/lib/Sema/SemaTemplate.cpp | 14 ++++++++++++- .../instantiate-non-type-template-parameter.cpp | 24 +++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'clang') diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index db9ed7e1efc..56410a2cfa4 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3061,9 +3061,21 @@ Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, return ExprError(); RefExpr = CreateBuiltinUnaryOp(Loc, UnaryOperator::AddrOf, move(RefExpr)); + + // We might need to perform a trailing qualification conversion, since + // the element type on the parameter could be more qualified than the + // element type in the expression we constructed. + if (IsQualificationConversion(((Expr*) RefExpr.get())->getType(), + ParamType.getUnqualifiedType())) { + Expr *RefE = RefExpr.takeAs(); + ImpCastExprToType(RefE, ParamType.getUnqualifiedType(), + CastExpr::CK_NoOp); + RefExpr = Owned(RefE); + } + assert(!RefExpr.isInvalid() && Context.hasSameType(((Expr*) RefExpr.get())->getType(), - ParamType)); + ParamType.getUnqualifiedType())); return move(RefExpr); } } diff --git a/clang/test/SemaTemplate/instantiate-non-type-template-parameter.cpp b/clang/test/SemaTemplate/instantiate-non-type-template-parameter.cpp index 414e62b13a0..cbadcde2c1c 100644 --- a/clang/test/SemaTemplate/instantiate-non-type-template-parameter.cpp +++ b/clang/test/SemaTemplate/instantiate-non-type-template-parameter.cpp @@ -9,6 +9,28 @@ public: } }; -int main(int argc, char *argv[]) { +void test_stringswitch(int argc, char *argv[]) { (void)StringSwitch(); } + +namespace PR6986 { + template + struct non_const_member_base + { + }; + + template + struct member: non_const_member_base + { + }; + + struct test_class + { + int int_member; + }; + typedef member< test_class,const int,&test_class::int_member > ckey_m; + void test() + { + ckey_m m; + } +} -- cgit v1.2.3