File tree 2 files changed +44
-0
lines changed
2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -1707,6 +1707,18 @@ class ConstraintRefersToContainingTemplateChecker
1707
1707
Result = true;
1708
1708
}
1709
1709
1710
+ void CheckNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
1711
+ assert(D->getDepth() <= TemplateDepth &&
1712
+ "Nothing should reference a value below the actual template depth, "
1713
+ "depth is likely wrong");
1714
+ if (D->getDepth() != TemplateDepth)
1715
+ Result = true;
1716
+
1717
+ // Necessary because the type of the NTTP might be what refers to the parent
1718
+ // constriant.
1719
+ TransformType(D->getType());
1720
+ }
1721
+
1710
1722
public:
1711
1723
using inherited = TreeTransform<ConstraintRefersToContainingTemplateChecker>;
1712
1724
@@ -1742,6 +1754,8 @@ class ConstraintRefersToContainingTemplateChecker
1742
1754
// unreachable should catch future instances/cases.
1743
1755
if (auto *TD = dyn_cast<TypedefNameDecl>(D))
1744
1756
TransformType(TD->getUnderlyingType());
1757
+ else if (auto *NTTPD = dyn_cast<NonTypeTemplateParmDecl>(D))
1758
+ CheckNonTypeTemplateParmDecl(NTTPD);
1745
1759
else if (auto *VD = dyn_cast<ValueDecl>(D))
1746
1760
TransformType(VD->getType());
1747
1761
else if (auto *TD = dyn_cast<TemplateDecl>(D))
Original file line number Diff line number Diff line change @@ -411,3 +411,33 @@ namespace RefersToParentInConstraint {
411
411
S<long > y;
412
412
}
413
413
} // namespace RefersToParentInConstraint
414
+
415
+ namespace NTTP {
416
+ struct Base {};
417
+ template <int N>
418
+ struct S : Base {
419
+ // N is from the parent template.
420
+ template <typename T>
421
+ friend int templ_func (Base&) requires(N > 0 )
422
+ { return 10 ; }
423
+ };
424
+
425
+ template <typename T>
426
+ struct U : Base {
427
+ template <T N>
428
+ friend int templ_func (Base&) requires(N>0 )
429
+ { return 10 ; }
430
+ };
431
+
432
+ void use () {
433
+ S<1 > s1;
434
+ templ_func<float >(s1);
435
+ S<2 > s2;
436
+ templ_func<float >(s2);
437
+
438
+ U<int > u1;
439
+ templ_func<1 >(u1);
440
+ U<short > u2;
441
+ templ_func<1 >(u2);
442
+ }
443
+ }
You can’t perform that action at this time.
0 commit comments