r339198 - [Sema] Ensure an auto non-type template parameter is dependent
Erik Pilkington via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 7 15:59:02 PDT 2018
Author: epilk
Date: Tue Aug 7 15:59:02 2018
New Revision: 339198
URL: http://llvm.org/viewvc/llvm-project?rev=339198&view=rev
Log:
[Sema] Ensure an auto non-type template parameter is dependent
The dependent auto was getting stripped away while rebuilding the template
parameter type, so substitute it in.
rdar://41852459
Differential revision: https://reviews.llvm.org/D50088
Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=339198&r1=339197&r2=339198&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Tue Aug 7 15:59:02 2018
@@ -974,7 +974,7 @@ NamedDecl *Sema::ActOnTypeParameter(Scop
QualType Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI,
SourceLocation Loc) {
if (TSI->getType()->isUndeducedType()) {
- // C++1z [temp.dep.expr]p3:
+ // C++17 [temp.dep.expr]p3:
// An id-expression is type-dependent if it contains
// - an identifier associated by name lookup with a non-type
// template-parameter declared with a type that contains a
@@ -9866,6 +9866,15 @@ bool Sema::RebuildTemplateParamsInCurren
if (!NewTSI)
return true;
+ if (NewTSI->getType()->isUndeducedType()) {
+ // C++17 [temp.dep.expr]p3:
+ // An id-expression is type-dependent if it contains
+ // - an identifier associated by name lookup with a non-type
+ // template-parameter declared with a type that contains a
+ // placeholder type (7.1.7.4),
+ NewTSI = SubstAutoTypeSourceInfo(NewTSI, Context.DependentTy);
+ }
+
if (NewTSI != NTTP->getTypeSourceInfo()) {
NTTP->setTypeSourceInfo(NewTSI);
NTTP->setType(NewTSI->getType());
Modified: cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp?rev=339198&r1=339197&r2=339198&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (original)
+++ cfe/trunk/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp Tue Aug 7 15:59:02 2018
@@ -335,3 +335,46 @@ namespace Nested {
void g(int, int);
using Int = A<int>::B<&g>::param2;
}
+
+namespace rdar41852459 {
+template <auto V> struct G {};
+
+template <class T> struct S {
+ template <auto V> void f() {
+ G<V> x;
+ }
+ template <auto *PV> void f2() {
+ G<PV> x;
+ }
+ template <decltype(auto) V> void f3() {
+ G<V> x;
+ }
+};
+
+template <auto *PV> struct I {};
+
+template <class T> struct K {
+ template <auto *PV> void f() {
+ I<PV> x;
+ }
+ template <auto V> void f2() {
+ I<V> x;
+ }
+ template <decltype(auto) V> void f3() {
+ I<V> x;
+ }
+};
+
+template <decltype(auto)> struct L {};
+template <class T> struct M {
+ template <auto *PV> void f() {
+ L<PV> x;
+ }
+ template <auto V> void f() {
+ L<V> x;
+ }
+ template <decltype(auto) V> void f() {
+ L<V> x;
+ }
+};
+}
More information about the cfe-commits
mailing list