|
26 | 26 | #include "clang/AST/ExprCXX.h"
|
27 | 27 | #include "clang/AST/PrettyPrinter.h"
|
28 | 28 | #include "clang/AST/Type.h"
|
| 29 | +#include "clang/Basic/Specifiers.h" |
29 | 30 | #include "clang/Index/IndexSymbol.h"
|
30 | 31 | #include "llvm/ADT/None.h"
|
31 | 32 | #include "llvm/ADT/Optional.h"
|
@@ -205,15 +206,23 @@ const FunctionDecl *getUnderlyingFunction(const Decl *D) {
|
205 | 206 | // Returns the decl that should be used for querying comments, either from index
|
206 | 207 | // or AST.
|
207 | 208 | const NamedDecl *getDeclForComment(const NamedDecl *D) {
|
208 |
| - if (auto *CTSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D)) |
209 |
| - if (!CTSD->isExplicitInstantiationOrSpecialization()) |
210 |
| - return CTSD->getTemplateInstantiationPattern(); |
211 |
| - if (auto *VTSD = llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) |
212 |
| - if (!VTSD->isExplicitInstantiationOrSpecialization()) |
213 |
| - return VTSD->getTemplateInstantiationPattern(); |
214 |
| - if (auto *FD = D->getAsFunction()) |
215 |
| - if (FD->isTemplateInstantiation()) |
216 |
| - return FD->getTemplateInstantiationPattern(); |
| 209 | + if (const auto *TSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D)) { |
| 210 | + // Template may not be instantiated e.g. if the type didn't need to be |
| 211 | + // complete; fallback to primary template. |
| 212 | + if (TSD->getTemplateSpecializationKind() == TSK_Undeclared) |
| 213 | + return TSD->getSpecializedTemplate(); |
| 214 | + if (const auto *TIP = TSD->getTemplateInstantiationPattern()) |
| 215 | + return TIP; |
| 216 | + } |
| 217 | + if (const auto *TSD = llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) { |
| 218 | + if (TSD->getTemplateSpecializationKind() == TSK_Undeclared) |
| 219 | + return TSD->getSpecializedTemplate(); |
| 220 | + if (const auto *TIP = TSD->getTemplateInstantiationPattern()) |
| 221 | + return TIP; |
| 222 | + } |
| 223 | + if (const auto *FD = D->getAsFunction()) |
| 224 | + if (const auto *TIP = FD->getTemplateInstantiationPattern()) |
| 225 | + return TIP; |
217 | 226 | return D;
|
218 | 227 | }
|
219 | 228 |
|
|
0 commit comments