Skip to content

Commit

Permalink
Fix crash in IncludeStyleRule related to class templates (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrdz committed Nov 22, 2016
1 parent b4b70e8 commit a62ce91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Rules/IncludeStyleRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ void IncludeStyleRule::run(const MatchFinder::MatchResult& result)
if (typeSourceInfo == nullptr)
return;

const CXXRecordDecl& baseDecl = *typeSourceInfo->getType()->getAsCXXRecordDecl();
SourceLocation baseLocation = baseDecl.getLocStart();
const Type& type = *typeSourceInfo->getType();
const CXXRecordDecl* baseDecl = type.getAsCXXRecordDecl();
if (baseDecl == nullptr)
return;

SourceLocation baseLocation = baseDecl->getLocStart();

StringRef baseFileName = m_context.sourceLocationHelper.GetCleanFilename(baseLocation, sourceManager);
if (! IsLocalInclude(baseFileName))
Expand Down
24 changes: 24 additions & 0 deletions Tests/include_style_rule_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,3 +561,27 @@ def test_base_class_header_and_config_file(self):
'system_header.h'
],
expected_errors = [])

def test_template_base_class_is_ignored(self):
self.assert_colobot_lint_result_with_project_headers_and_fake_header_source(
main_file_lines = [
'#include "def/src.h"'
],
main_file = 'def/src.cpp',
project_headers = {
'def/src.h': [
'template<typename T>',
'class Base',
'{',
' T a;',
'};',
'template<typename T>'
'class Derived : public Base<T>',
'{',
'};',
'Derived<int> d;'
],
},
system_header_files = [],
expected_errors = [])

0 comments on commit a62ce91

Please sign in to comment.