[clang] [clang][modules] Fix std::initializer_list recognition if it's exported out of a module (PR #118537)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 3 12:02:58 PST 2024
https://github.com/jijjijj created https://github.com/llvm/llvm-project/pull/118537
If the std::initializer_list is exported out of module, its `DeclContext` is not a namespace as `Sema::isStdInitializerList` expects, but an `Decl::Kind::Export` and only its parent is a namespace. So this commit makes `Sema::isStdInitializerList` account for that.
I'm really new to clang so I'm not 100% sure that was the issue, it seems so and it fixes compilation. Also I probably need to add tests but I'd like someone to approve the idea first.
Fixes https://github.com/llvm/llvm-project/issues/118218
>From d0a3059a10b7ceeb7e9c27068266f8c41e794203 Mon Sep 17 00:00:00 2001
From: jijjijj <realjijjijj at gmail.com>
Date: Tue, 3 Dec 2024 22:57:34 +0300
Subject: [PATCH] Fix std::initializer_list recognition if it's exported out of
a module
If the std::initializer_list is exported out of module, its DeclContext is not a namespace as `Sema::isStdInitializerList` expects, but an `Decl::Kind::Export` and only its parent is a namespace. So this commit makes `Sema::isStdInitializerList` account for that.
---
clang/lib/Sema/SemaDeclCXX.cpp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7e8e321c4b90e6..4572229562ed3b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11919,8 +11919,12 @@ bool Sema::isStdInitializerList(QualType Ty, QualType *Element) {
CXXRecordDecl *TemplateClass = Template->getTemplatedDecl();
if (TemplateClass->getIdentifier() !=
&PP.getIdentifierTable().get("initializer_list") ||
- !getStdNamespace()->InEnclosingNamespaceSetOf(
- TemplateClass->getDeclContext()))
+ !(getStdNamespace()->InEnclosingNamespaceSetOf(
+ TemplateClass->getDeclContext()) ||
+ // if decl context is an export from module we need to check the parent
+ (TemplateClass->getDeclContext()->getDeclKind() == Decl::Kind::Export &&
+ getStdNamespace()->InEnclosingNamespaceSetOf(
+ TemplateClass->getDeclContext()->getParent()))))
return false;
// This is a template called std::initializer_list, but is it the right
// template?
More information about the cfe-commits
mailing list