[PATCH] D130585: [Sema] Return primary merged decl as canonical for concepts
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 27 03:31:57 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42f87bb62d07: [Sema] Return primary merged decl as canonical for concepts (authored by ilya-biryukov).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130585/new/
https://reviews.llvm.org/D130585
Files:
clang/include/clang/AST/DeclTemplate.h
clang/lib/Sema/SemaTemplate.cpp
clang/test/Modules/merge-concepts.cpp
Index: clang/test/Modules/merge-concepts.cpp
===================================================================
--- clang/test/Modules/merge-concepts.cpp
+++ clang/test/Modules/merge-concepts.cpp
@@ -28,6 +28,10 @@
export *
header "concepts.h"
}
+ module "compare" {
+ export *
+ header "compare.h"
+ }
module "format" {
export *
header "format.h"
@@ -47,19 +51,34 @@
#define SAME_AS_H
template <class T, class U>
-concept same_as = __is_same(T, U);
+concept same_as_impl = __is_same(T, U);
+template <class T, class U>
+concept same_as = same_as_impl<T, U> && same_as_impl<U, T>;
#endif // SAME_AS_H
+
+//--- compare.h
+#ifndef COMPARE_H
+#define COMPARE_H
+
+#include "same_as.h"
+#include "concepts.h"
+
+template <class T> void foo()
+ requires same_as<T, int>
+{}
+#endif // COMPARE_H
+
//--- format.h
#ifndef FORMAT_H
#define FORMAT_H
-#include "concepts.h"
#include "same_as.h"
+#include "concepts.h"
-template <class T> void foo()
+template <class T> void bar()
requires same_as<T, int>
{}
-#endif // FORMAT_H
\ No newline at end of file
+#endif // FORMAT_H
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -8754,7 +8754,8 @@
// Other decls (e.g. namespaces) also have this shortcoming.
return;
}
- Context.setPrimaryMergedDecl(NewDecl, OldConcept);
+ // We unwrap canonical decl late to check for module visibility.
+ Context.setPrimaryMergedDecl(NewDecl, OldConcept->getCanonicalDecl());
}
/// \brief Strips various properties off an implicit instantiation
Index: clang/include/clang/AST/DeclTemplate.h
===================================================================
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -3287,8 +3287,12 @@
return isa<TemplateTypeParmDecl>(getTemplateParameters()->getParam(0));
}
- ConceptDecl *getCanonicalDecl() override { return getFirstDecl(); }
- const ConceptDecl *getCanonicalDecl() const { return getFirstDecl(); }
+ ConceptDecl *getCanonicalDecl() override {
+ return cast<ConceptDecl>(getPrimaryMergedDecl(this));
+ }
+ const ConceptDecl *getCanonicalDecl() const {
+ return const_cast<ConceptDecl *>(this)->getCanonicalDecl();
+ }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130585.447986.patch
Type: text/x-patch
Size: 2467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220727/5ea78a40/attachment.bin>
More information about the cfe-commits
mailing list