Skip to content

Commit

Permalink
Merge pull request #366 from andreasfertig/fixIssue365
Browse files Browse the repository at this point in the history
Fixed #365: `CXXDeductionGuideDecl` appeared in the middle of a template
  • Loading branch information
andreasfertig authored Dec 11, 2020
2 parents b0f8a03 + 77df40d commit ec409c1
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
14 changes: 13 additions & 1 deletion TemplateHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,21 @@ void TemplateHandler::run(const MatchFinder::MatchResult& result)
return;
}

// Figure out whether we are looking at a CXXDeductionGuideDecl. If so, ensure that the deduction guide comes
// after the primary template declaration.
const Decl* endLocDecl = functionDecl;
if(const auto* deductionGuide = dyn_cast_or_null<CXXDeductionGuideDecl>(functionDecl)) {
const auto* deducedTemplate = deductionGuide->getDeducedTemplate();

// deduction guide must follow after the template declaration
if(deducedTemplate->getEndLoc() > deductionGuide->getEndLoc()) {
endLocDecl = deducedTemplate;
}
}

OutputFormatHelper outputFormatHelper = InsertInstantiatedTemplate(functionDecl);
const auto endOfCond = FindLocationAfterRBrace(
GetEndLoc(functionDecl),
GetEndLoc(endLocDecl),
result,
isa<CXXDeductionGuideDecl>(
functionDecl)); // if we lift the "not getBody()" restriction above we need to take this in account
Expand Down
13 changes: 13 additions & 0 deletions tests/Issue365.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
template<long Len = 128, long BlockSize = 128, class T = wchar_t>
class String {
public:
bool Format(const wchar_t FormatStr[], ...) { return true; }
};

void FTest() {
double d{};

String s;
s.Format(L"%i", d);
}

39 changes: 39 additions & 0 deletions tests/Issue365.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
template<long Len = 128, long BlockSize = 128, class T = wchar_t>
class String {
public:
bool Format(const wchar_t FormatStr[], ...) { return true; }
};

/* First instantiated from: Issue365.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
class String<128, 128, wchar_t>
{

public:
inline bool Format(const wchar_t * FormatStr, ...)
{
return true;
}

// inline constexpr String() noexcept = default;
};

#endif



/* First instantiated from: Issue365.cpp:10 */
#ifdef INSIGHTS_USE_TEMPLATE
template<>
String -> String<128, 128, wchar_t>;
#endif

void FTest()
{
double d = {};
String<128, 128, wchar_t> s = String<128, 128, wchar_t>();
s.Format(L"%i", d);
}


0 comments on commit ec409c1

Please sign in to comment.