aboutsummaryrefslogtreecommitdiff
path: root/clang/include
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2022-07-27 12:11:42 +0200
committerTom Stellard <tstellar@redhat.com>2022-08-08 11:31:42 -0700
commit3e6ea8aff3d534c56e04e39424a27761facc4101 (patch)
treec4ca6f57403eb9bbad820625e03514876e067c09 /clang/include
parent207f96e8fac08db23bd2a8edc700e162f135ef62 (diff)
downloadllvm-3e6ea8aff3d534c56e04e39424a27761facc4101.zip
llvm-3e6ea8aff3d534c56e04e39424a27761facc4101.tar.gz
llvm-3e6ea8aff3d534c56e04e39424a27761facc4101.tar.bz2
[Sema] Return primary merged decl as canonical for concepts
Otherwise we get invalid results for ODR checks. See changed test for an example: despite the fact that we merge the first concept, its **uses** were considered different by `Profile`, leading to redefinition errors. After this change, canonical decl for a concept can come from a different module and may not be visible. This behavior looks suspicious, but does not break any tests. We might want to add a mechanism to make the canonical concept declaration visible if we find code that relies on this invariant. Additionally make sure we always merge with the canonical declaration to avoid chains of merged concepts being reported as redefinitions. An example was added to the test. Also change the order of includes in the test. Importing a moduralized header before its textual part causes the include guard macro to be exported and the corresponding `#include` becomes a no-op. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D130585 (cherry picked from commit 42f87bb62d0719848842da60d2a8180b9e4d7c52)
Diffstat (limited to 'clang/include')
-rw-r--r--clang/include/clang/AST/DeclTemplate.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h
index 725bb0b..baed5ca 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -3287,8 +3287,12 @@ public:
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()); }