@@ -481,6 +481,17 @@ static clang::Decl* GetPreviousDeclInContext(const clang::Decl* D)
481
481
return nullptr ;
482
482
}
483
483
484
+ bool IsExplicit (const clang::Decl* D)
485
+ {
486
+ using namespace clang ;
487
+
488
+ auto CTS = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D);
489
+ return !CTS ||
490
+ CTS->getSpecializationKind () == TSK_ExplicitSpecialization ||
491
+ CTS->getSpecializationKind () == TSK_ExplicitInstantiationDeclaration ||
492
+ CTS->getSpecializationKind () == TSK_ExplicitInstantiationDefinition;
493
+ }
494
+
484
495
static clang::SourceLocation GetDeclStartLocation (clang::CompilerInstance* C,
485
496
const clang::Decl* D)
486
497
{
@@ -500,7 +511,7 @@ static clang::SourceLocation GetDeclStartLocation(clang::CompilerInstance* C,
500
511
return lineBeginLoc;
501
512
502
513
auto prevDecl = GetPreviousDeclInContext (D);
503
- if (!prevDecl)
514
+ if (!prevDecl || ! IsExplicit (prevDecl) )
504
515
return lineBeginLoc;
505
516
506
517
auto prevDeclEndLoc = SM.getExpansionLoc (prevDecl->getLocEnd ());
@@ -816,15 +827,18 @@ void Parser::WalkRecord(const clang::RecordDecl* Record, Class* RC)
816
827
if (Record->isImplicit ())
817
828
return ;
818
829
819
- auto headStartLoc = GetDeclStartLocation (c.get (), Record);
820
- auto headEndLoc = Record->getLocation (); // identifier location
821
- auto bodyEndLoc = Record->getLocEnd ();
830
+ if (IsExplicit (Record))
831
+ {
832
+ auto headStartLoc = GetDeclStartLocation (c.get (), Record);
833
+ auto headEndLoc = Record->getLocation (); // identifier location
834
+ auto bodyEndLoc = Record->getLocEnd ();
822
835
823
- auto headRange = clang::SourceRange (headStartLoc, headEndLoc);
824
- auto bodyRange = clang::SourceRange (headEndLoc, bodyEndLoc);
836
+ auto headRange = clang::SourceRange (headStartLoc, headEndLoc);
837
+ auto bodyRange = clang::SourceRange (headEndLoc, bodyEndLoc);
825
838
826
- HandlePreprocessedEntities (RC, headRange, MacroLocation::ClassHead);
827
- HandlePreprocessedEntities (RC, bodyRange, MacroLocation::ClassBody);
839
+ HandlePreprocessedEntities (RC, headRange, MacroLocation::ClassHead);
840
+ HandlePreprocessedEntities (RC, bodyRange, MacroLocation::ClassBody);
841
+ }
828
842
829
843
auto & Sema = c->getSema ();
830
844
@@ -3429,8 +3443,17 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
3429
3443
Decl->USR = GetDeclUSR (D);
3430
3444
Decl->isImplicit = D->isImplicit ();
3431
3445
Decl->location = SourceLocation (D->getLocation ().getRawEncoding ());
3432
- Decl->lineNumberStart = c->getSourceManager ().getExpansionLineNumber (D->getLocStart ());
3433
- Decl->lineNumberEnd = c->getSourceManager ().getExpansionLineNumber (D->getLocEnd ());
3446
+ auto IsDeclExplicit = IsExplicit (D);
3447
+ if (IsDeclExplicit)
3448
+ {
3449
+ Decl->lineNumberStart = c->getSourceManager ().getExpansionLineNumber (D->getLocStart ());
3450
+ Decl->lineNumberEnd = c->getSourceManager ().getExpansionLineNumber (D->getLocEnd ());
3451
+ }
3452
+ else
3453
+ {
3454
+ Decl->lineNumberStart = -1 ;
3455
+ Decl->lineNumberEnd = -1 ;
3456
+ }
3434
3457
3435
3458
if (Decl->PreprocessedEntities .empty () && !D->isImplicit ())
3436
3459
{
@@ -3442,7 +3465,7 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
3442
3465
{
3443
3466
// Ignore function parameters as we already walk their preprocessed entities.
3444
3467
}
3445
- else
3468
+ else if (IsDeclExplicit)
3446
3469
{
3447
3470
auto startLoc = GetDeclStartLocation (c.get (), D);
3448
3471
auto endLoc = D->getLocEnd ();
@@ -3452,7 +3475,8 @@ void Parser::HandleDeclaration(const clang::Decl* D, Declaration* Decl)
3452
3475
}
3453
3476
}
3454
3477
3455
- HandleOriginalText (D, Decl);
3478
+ if (IsDeclExplicit)
3479
+ HandleOriginalText (D, Decl);
3456
3480
HandleComments (D, Decl);
3457
3481
3458
3482
if (const clang::ValueDecl *VD = clang::dyn_cast_or_null<clang::ValueDecl>(D))
0 commit comments