@@ -2921,10 +2921,15 @@ void Parser::CompleteIfSpecializationType(const clang::QualType& QualType)
2921
2921
CTS->isCompleteDefinition ())
2922
2922
return ;
2923
2923
2924
- auto Diagnostics = c->getSema ().getDiagnostics ().getClient ();
2925
- auto SemaDiagnostics = static_cast <::DiagnosticConsumer*>(Diagnostics);
2924
+ auto existingClient = c->getSema ().getDiagnostics ().getClient ();
2925
+ std::unique_ptr<::DiagnosticConsumer> SemaDiagnostics (new ::DiagnosticConsumer ());
2926
+ SemaDiagnostics-> Decl = CTS;
2927
+ c->getSema ().getDiagnostics ().setClient (SemaDiagnostics.get (), false );
2928
+
2926
2929
c->getSema ().InstantiateClassTemplateSpecialization (CTS->getBeginLoc (),
2927
2930
CTS, TSK_ImplicitInstantiation, false );
2931
+
2932
+ c->getSema ().getDiagnostics ().setClient (existingClient, false );
2928
2933
}
2929
2934
2930
2935
Parameter* Parser::WalkParameter (const clang::ParmVarDecl* PVD,
@@ -3053,9 +3058,11 @@ void Parser::MarkValidity(Function* F)
3053
3058
c->getSourceManager ().isInSystemHeader (FD->getBeginLoc ()))
3054
3059
return ;
3055
3060
3056
- auto Diagnostics = c->getSema ().getDiagnostics ().getClient ();
3057
- auto SemaDiagnostics = static_cast < ::DiagnosticConsumer*>(Diagnostics );
3061
+ auto existingClient = c->getSema ().getDiagnostics ().getClient ();
3062
+ std::unique_ptr<::DiagnosticConsumer> SemaDiagnostics ( new ::DiagnosticConsumer () );
3058
3063
SemaDiagnostics->Decl = FD;
3064
+ c->getSema ().getDiagnostics ().setClient (SemaDiagnostics.get (), false );
3065
+
3059
3066
auto TUScope = c->getSema ().TUScope ;
3060
3067
std::stack<Scope> Scopes = GetScopesFor (FD);
3061
3068
c->getSema ().TUScope = &Scopes.top ();
@@ -3068,6 +3075,8 @@ void Parser::MarkValidity(Function* F)
3068
3075
std::unordered_set<Stmt*> Bodies{ 0 };
3069
3076
F->isInvalid = IsInvalid (FD->getBody (), Bodies);
3070
3077
}
3078
+
3079
+ c->getSema ().getDiagnostics ().setClient (existingClient, false );
3071
3080
}
3072
3081
3073
3082
void Parser::WalkFunction (const clang::FunctionDecl* FD, Function* F,
@@ -4154,19 +4163,18 @@ ParserResult* Parser::ParseHeader(const std::vector<std::string>& SourceFiles)
4154
4163
4155
4164
c->createSema (clang::TU_Complete, 0 );
4156
4165
4157
- auto DiagClient = new DiagnosticConsumer ();
4158
- c->getDiagnostics ().setClient (DiagClient);
4166
+ std::unique_ptr<::DiagnosticConsumer> DiagClient ( new :: DiagnosticConsumer () );
4167
+ c->getDiagnostics ().setClient (DiagClient. get (), false );
4159
4168
4160
- clang::DiagnosticConsumer* client = c->getDiagnostics ().getClient ();
4161
- client->BeginSourceFile (c->getLangOpts (), &c->getPreprocessor ());
4169
+ DiagClient->BeginSourceFile (c->getLangOpts (), &c->getPreprocessor ());
4162
4170
4163
4171
ParseAST (c->getSema ());
4164
4172
4165
- client ->EndSourceFile ();
4173
+ DiagClient ->EndSourceFile ();
4166
4174
4167
4175
HandleDiagnostics (res);
4168
4176
4169
- if (client ->getNumErrors () != 0 )
4177
+ if (DiagClient ->getNumErrors () != 0 )
4170
4178
{
4171
4179
res->kind = ParserResultKind::Error;
4172
4180
return res;
0 commit comments