Skip to content

Commit e55b194

Browse files
authored
[Clang] Fix template arguments collection for out-of-line declarations (#147463)
We were using the lexical DC as the starting point of template argument collection when comparing declarations. This caused an issue that template arguments from out-of-line declarations are ignored when substituting into the constraints, which in turn led to expression mismatching. Fixes #145521
1 parent e476f96 commit e55b194

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ Bug Fixes to C++ Support
898898
- Clang now correctly parses arbitrary order of ``[[]]``, ``__attribute__`` and ``alignas`` attributes for declarations (#GH133107)
899899
- Fixed a crash when forming an invalid function type in a dependent context. (#GH138657) (#GH115725) (#GH68852)
900900
- Fixed a function declaration mismatch that caused inconsistencies between concepts and variable template declarations. (#GH139476)
901+
- Fixed an out-of-line declaration mismatch involving nested template parameters. (#GH145521)
901902
- Clang no longer segfaults when there is a configuration mismatch between modules and their users (http://crbug.com/400353616).
902903
- Fix an incorrect deduction when calling an explicit object member function template through an overload set address.
903904
- Fixed bug in constant evaluation that would allow using the value of a

clang/lib/Sema/SemaConcept.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ static const Expr *SubstituteConstraintExpressionWithoutSatisfaction(
898898
Sema &S, const Sema::TemplateCompareNewDeclInfo &DeclInfo,
899899
const Expr *ConstrExpr) {
900900
MultiLevelTemplateArgumentList MLTAL = S.getTemplateInstantiationArgs(
901-
DeclInfo.getDecl(), DeclInfo.getLexicalDeclContext(), /*Final=*/false,
901+
DeclInfo.getDecl(), DeclInfo.getDeclContext(), /*Final=*/false,
902902
/*Innermost=*/std::nullopt,
903903
/*RelativeToPrimary=*/true,
904904
/*Pattern=*/nullptr, /*ForConstraintInstantiation=*/true,

clang/test/SemaTemplate/concepts-out-of-line-def.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,28 @@ template <typename T> requires moo::baa<T>
868868
void moo::caw() {}
869869

870870
}
871+
872+
namespace GH145521 {
873+
874+
template <typename X>
875+
concept is_valid = true;
876+
877+
template<typename T>
878+
class Nesting
879+
{
880+
public:
881+
template<typename Q> requires is_valid<Q>
882+
class Inner;
883+
884+
template<typename Q> requires is_valid<Q>
885+
friend class Inner2;
886+
};
887+
888+
template<typename T>
889+
template<typename Q> requires is_valid<Q>
890+
class Nesting<T>::Inner {};
891+
892+
template<typename Q> requires is_valid<Q>
893+
class Inner2 {};
894+
895+
}

0 commit comments

Comments
 (0)