[clang] [Clang] Fix Microsoft ABI inheritance model when member pointer is used in a base specifier (PR #91990)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 13 09:22:02 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 754ff0f54a4b09a8e4b00783475c51f66b949b66 a5347082aa47a7aa525ece818f91fb6fdd5fdb0c -- clang/include/clang/AST/DeclCXX.h clang/lib/AST/DeclCXX.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaType.cpp clang/test/SemaCXX/complete-member-pointers.cpp clang/test/SemaCXX/member-pointer-ms.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h
index 45b3b47ed5..81669b1f60 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -599,7 +599,9 @@ public:
return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases();
}
- void setIsParsingBaseSpecifiers(bool to = true) { data().IsParsingBaseSpecifiers = to; }
+ void setIsParsingBaseSpecifiers(bool to = true) {
+ data().IsParsingBaseSpecifiers = to;
+ }
bool isParsingBaseSpecifiers() const {
return data().IsParsingBaseSpecifiers;
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 681b980314..a28503b5b4 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2335,24 +2335,26 @@ void Parser::ParseClassSpecifier(tok::TokenKind TagTokKind,
}
namespace {
- struct ParsingBaseSpecifiersGuard {
- CXXRecordDecl *RD = nullptr;
- ParsingBaseSpecifiersGuard(Sema& S, Decl *D) {
- if (D) {
- S.AdjustDeclIfTemplate(D);
- RD = cast<CXXRecordDecl>(D);
- assert(!RD->isParsingBaseSpecifiers() && "Recursively parsing base specifiers of the same class?");
- RD->setIsParsingBaseSpecifiers(true);
- }
+struct ParsingBaseSpecifiersGuard {
+ CXXRecordDecl *RD = nullptr;
+ ParsingBaseSpecifiersGuard(Sema &S, Decl *D) {
+ if (D) {
+ S.AdjustDeclIfTemplate(D);
+ RD = cast<CXXRecordDecl>(D);
+ assert(!RD->isParsingBaseSpecifiers() &&
+ "Recursively parsing base specifiers of the same class?");
+ RD->setIsParsingBaseSpecifiers(true);
}
- ~ParsingBaseSpecifiersGuard() {
- if (RD) {
- assert(RD->isParsingBaseSpecifiers() && "Stopped parsing base specifiers before exiting ParseBaseClause?");
- RD->setIsParsingBaseSpecifiers(false);
- }
+ }
+ ~ParsingBaseSpecifiersGuard() {
+ if (RD) {
+ assert(RD->isParsingBaseSpecifiers() &&
+ "Stopped parsing base specifiers before exiting ParseBaseClause?");
+ RD->setIsParsingBaseSpecifiers(false);
}
- };
-}
+ }
+};
+} // namespace
/// ParseBaseClause - Parse the base-clause of a C++ class [C++ class.derived].
///
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 0a801f1797..e00ee46c9d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -9465,17 +9465,21 @@ bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
if (!MPTy->getClass()->isDependentType()) {
// We lock in the inheritance model once somebody has asked us to ensure
// that a pointer-to-member type is complete.
- if (Context.getTargetInfo().getCXXABI().isMicrosoft() || getLangOpts().CompleteMemberPointers) {
+ if (Context.getTargetInfo().getCXXABI().isMicrosoft() ||
+ getLangOpts().CompleteMemberPointers) {
QualType Class = QualType(MPTy->getClass(), 0);
(void)isCompleteType(Loc, Class);
CXXRecordDecl *RD = MPTy->getMostRecentCXXRecordDecl();
assignInheritanceModel(*this, RD);
- if (getLangOpts().CompleteMemberPointers && RD->getMSInheritanceModel() == MSInheritanceModel::Unspecified) {
+ if (getLangOpts().CompleteMemberPointers &&
+ RD->getMSInheritanceModel() == MSInheritanceModel::Unspecified) {
if (RD->hasDefinition() && RD->isParsingBaseSpecifiers()) {
Diag(Loc, diag::err_memptr_incomplete) << Class;
- Diag(RD->getDefinition()->getLocation(), diag::note_memptr_incomplete_until_bases);
- } else if (!RequireCompleteType(Loc, Class, diag::err_memptr_incomplete))
+ Diag(RD->getDefinition()->getLocation(),
+ diag::note_memptr_incomplete_until_bases);
+ } else if (!RequireCompleteType(Loc, Class,
+ diag::err_memptr_incomplete))
Diag(Loc, diag::err_memptr_incomplete) << Class;
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/91990
More information about the cfe-commits
mailing list