summaryrefslogtreecommitdiffstats
path: root/src/RunClang.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-12-08 14:45:45 (GMT)
committerBrad King <brad.king@kitware.com>2014-12-08 14:55:31 (GMT)
commit01f991852c288a061e121e0c6017da32b34bb3da (patch)
tree464ec2a615c09ad439cf947b6ac2b3c82be6e87a /src/RunClang.cxx
parent825cca7df68c0282339e3d0ec64e75f40fd57ed9 (diff)
downloadCastXML-01f991852c288a061e121e0c6017da32b34bb3da.zip
CastXML-01f991852c288a061e121e0c6017da32b34bb3da.tar.gz
CastXML-01f991852c288a061e121e0c6017da32b34bb3da.tar.bz2
RunClang: Refactor definition of implicit members
Use clang::Sema::PerformPendingInstantiations before we attempt to add implicit member definitions so any real errors show up first. Then set SuppressAllDiagnostics to suppress errors caused by the following. Iterate over all members of one class at a time in order of completion of class definition (bases before derived classes). Force definition of each member using clang::Sema::MarkFunctionReferenced followed by another call to clang::Sema::PerformPendingInstantiations to ensure that members formed by implicitly instantiated templates are completed. Clang will mark any failed declaration as invalid, allowing us to exclude it from the output. This works both for implicit and explicit members. Update the test suite to mark test cases that are no longer 'broken'. According to discussion on the Clang cfe-commits mailing list: [PATCH] Add DiagnosticSuppressionScope RAII class http://thread.gmane.org/gmane.comp.compilers.clang.scm/110832/focus=111112 this approach may depend on non-guaranteed behavior. By iterating over members in order of class definition, we mark any bad special members invalid in base classes so that when Clang processes those in derived classes the invalid members are only one "step" away. Hopefully this behavior will be easier to preserve if Clang changes in the future.
Diffstat (limited to 'src/RunClang.cxx')
-rw-r--r--src/RunClang.cxx40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/RunClang.cxx b/src/RunClang.cxx
index b73d801..8346b09 100644
--- a/src/RunClang.cxx
+++ b/src/RunClang.cxx
@@ -61,40 +61,16 @@ public:
clang::Sema& sema = this->CI.getSema();
sema.ForceDeclarationOfImplicitMembers(rd);
-# define DEFINE_IMPLICIT(name, decl) do { \
- clang::Sema::SFINAETrap trap(sema, /*AccessChecking=*/ true); \
- sema.DefineImplicit##name(clang::SourceLocation(), (decl)); \
- if (trap.hasErrorOccurred()) { \
- (decl)->setInvalidDecl(); \
- } \
- } while(0)
-
for(clang::DeclContext::decl_iterator i = rd->decls_begin(),
e = rd->decls_end(); i != e; ++i) {
clang::CXXMethodDecl* m = clang::dyn_cast<clang::CXXMethodDecl>(*i);
- if(m && m->isImplicit() && !m->isDeleted() &&
- !m->doesThisDeclarationHaveABody()) {
- if (clang::CXXConstructorDecl* c =
- clang::dyn_cast<clang::CXXConstructorDecl>(m)) {
- if (c->isDefaultConstructor()) {
- DEFINE_IMPLICIT(DefaultConstructor, c);
- } else if (c->isCopyConstructor()) {
- DEFINE_IMPLICIT(CopyConstructor, c);
- } else if (c->isMoveConstructor()) {
- DEFINE_IMPLICIT(MoveConstructor, c);
- }
- } else if (clang::CXXDestructorDecl* d =
- clang::dyn_cast<clang::CXXDestructorDecl>(m)) {
- DEFINE_IMPLICIT(Destructor, d);
- } else if (m->isCopyAssignmentOperator()) {
- DEFINE_IMPLICIT(CopyAssignment, m);
- } else if (m->isMoveAssignmentOperator()) {
- DEFINE_IMPLICIT(MoveAssignment, m);
- }
+ if(m && !m->isDeleted() && !m->isInvalidDecl()) {
+ /* Ensure the member is defined. */
+ sema.MarkFunctionReferenced(clang::SourceLocation(), m);
+ /* Finish implicitly instantiated member. */
+ sema.PerformPendingInstantiations();
}
}
-
-# undef DEFINE_IMPLICIT
}
void HandleTagDeclDefinition(clang::TagDecl* d) {
@@ -108,6 +84,12 @@ public:
void HandleTranslationUnit(clang::ASTContext& ctx) {
clang::Sema& sema = this->CI.getSema();
+ // Perform instantiations needed by the original translation unit.
+ sema.PerformPendingInstantiations();
+
+ // Suppress diagnostics from below extensions to the translation unit.
+ sema.getDiagnostics().setSuppressAllDiagnostics(true);
+
// Add implicit members to classes.
for(clang::CXXRecordDecl* rd : this->Classes) {
this->AddImplicitMembers(rd);