File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ functionStatic:*/ui_fileview.h
16
16
valueFlowBailout
17
17
valueFlowBailoutIncompleteVar
18
18
autoNoType
19
+ # ticket 11631
20
+ templateInstantiation:test/testutils.cpp
19
21
20
22
naming-varname:externals/simplecpp/simplecpp.h
21
23
naming-privateMemberVariable:externals/simplecpp/simplecpp.h
@@ -32,4 +34,4 @@ functionStatic:externals/tinyxml2/tinyxml2.h
32
34
invalidPrintfArgType_uint:externals/tinyxml2/tinyxml2.cpp
33
35
funcArgNamesDifferent:externals/tinyxml2/tinyxml2.cpp
34
36
nullPointerRedundantCheck:externals/tinyxml2/tinyxml2.cpp
35
- knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp
37
+ knownConditionTrueFalse:externals/tinyxml2/tinyxml2.cpp
Original file line number Diff line number Diff line change @@ -774,6 +774,19 @@ static bool areAllParamsTypes(const std::vector<const Token *> ¶ms)
774
774
});
775
775
}
776
776
777
+ static bool isTemplateInstantion (const Token* tok)
778
+ {
779
+ if (!tok->isName () || (tok->isKeyword () && !tok->isOperatorKeyword ()))
780
+ return false ;
781
+ if (Token::Match (tok->tokAt (-1 ), " %type% %name% ::|<" ))
782
+ return true ;
783
+ if (Token::Match (tok->tokAt (-2 ), " [,:] private|protected|public %name% ::|<" ))
784
+ return true ;
785
+ if (Token::Match (tok->tokAt (-1 ), " (|{|}|;|=|>|<<|:|.|*|&|return|<|,|!|[ %name% ::|<|(" ))
786
+ return true ;
787
+ return Token::Match (tok->tokAt (-2 ), " (|{|}|;|=|<<|:|.|*|&|return|<|,|!|[ :: %name% ::|<|(" );
788
+ }
789
+
777
790
void TemplateSimplifier::getTemplateInstantiations ()
778
791
{
779
792
std::multimap<std::string, const TokenAndName *> functionNameMap;
@@ -830,9 +843,7 @@ void TemplateSimplifier::getTemplateInstantiations()
830
843
Token *tok2 = Token::findsimplematch (tok->tokAt (2 ), " ;" );
831
844
if (tok2)
832
845
tok = tok2;
833
- } else if (Token::Match (tok->previous (), " (|{|}|;|=|>|<<|:|.|*|&|return|<|,|!|[ %name% ::|<|(" ) ||
834
- Token::Match (tok->previous (), " %type% %name% ::|<" ) ||
835
- Token::Match (tok->tokAt (-2 ), " [,:] private|protected|public %name% ::|<" )) {
846
+ } else if (isTemplateInstantion (tok)) {
836
847
if (!tok->scopeInfo ())
837
848
syntaxError (tok);
838
849
std::string scopeName = tok->scopeInfo ()->name ;
Original file line number Diff line number Diff line change @@ -241,6 +241,7 @@ class TestSimplifyTemplate : public TestFixture {
241
241
TEST_CASE (template_namespace_10);
242
242
TEST_CASE (template_namespace_11); // #7145
243
243
TEST_CASE (template_namespace_12);
244
+ TEST_CASE (template_namespace_13);
244
245
TEST_CASE (template_pointer_type);
245
246
TEST_CASE (template_array_type);
246
247
@@ -5313,6 +5314,22 @@ class TestSimplifyTemplate : public TestFixture {
5313
5314
tok (code));
5314
5315
}
5315
5316
5317
+ void template_namespace_13 () {
5318
+ const char code[] = " namespace N {\n " // #13593
5319
+ " template<typename T>\n "
5320
+ " struct S {\n "
5321
+ " using U = T*;\n "
5322
+ " };\n "
5323
+ " }\n "
5324
+ " ::N::S<int>::U u;\n " ;
5325
+ ASSERT_EQUALS (" namespace N { "
5326
+ " struct S<int> ; "
5327
+ " } "
5328
+ " int * u ; "
5329
+ " struct N :: S<int> { } ;" ,
5330
+ tok (code));
5331
+ }
5332
+
5316
5333
void template_pointer_type () {
5317
5334
const char code[] = " template<class T> void foo(const T x) {}\n "
5318
5335
" void bar() { foo<int*>(0); }" ;
You can’t perform that action at this time.
0 commit comments