[clang] [clang]get non-injected-class before finding instantiated decl (PR #70886)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 31 20:02:01 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Congcong Cai (HerrCai0907)
<details>
<summary>Changes</summary>
Fixes #<!-- -->21483
---
Full diff: https://github.com/llvm/llvm-project/pull/70886.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+2)
- (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+3)
- (modified) clang/test/SemaCXX/friend.cpp (+16)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc28bb567f6932a..a8ae5fb2596c580 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -533,6 +533,8 @@ Bug Fixes in This Version
Fixes (`#67687 <https://github.com/llvm/llvm-project/issues/67687>`_)
- Fix crash from constexpr evaluator evaluating uninitialized arrays as rvalue.
Fixes (`#67317 <https://github.com/llvm/llvm-project/issues/67317>`_)
+- Fix an issue when do name lookup which scope resolution operator in friend function.
+ Fixes (`#21483 <https://github.com/llvm/llvm-project/issues/21483>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 78a7892a35a320b..83dac8ece06b20b 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -6191,6 +6191,9 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
}
if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D)) {
+ if (Record->isInjectedClassName())
+ Record = cast<CXXRecordDecl>(Record->getDeclContext());
+
if (!Record->isDependentContext())
return D;
diff --git a/clang/test/SemaCXX/friend.cpp b/clang/test/SemaCXX/friend.cpp
index 367d6a6c1807c92..7b8e50322c4f8f9 100644
--- a/clang/test/SemaCXX/friend.cpp
+++ b/clang/test/SemaCXX/friend.cpp
@@ -429,3 +429,19 @@ namespace qualified_friend_no_match {
friend void Y::f(double); // expected-error {{friend declaration of 'f' does not match any declaration in 'qualified_friend_no_match::Y'}}
};
}
+
+namespace gh21483 {
+template <typename I>
+struct B {
+ struct mixin {
+ int type;
+ friend void foo(B<I>::mixin it) {
+ (void)it.mixin::type;
+ }
+ };
+};
+
+void bar() {
+ foo(B<int>::mixin{});
+}
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/70886
More information about the cfe-commits
mailing list