@@ -314,6 +314,8 @@ class TestSimplifyTemplate : public TestFixture {
314314 TEST_CASE (explicitBool2);
315315
316316 TEST_CASE (templateArgPreserveType); // #13882 - type of template argument
317+
318+ TEST_CASE (dumpTemplateArgFrom);
317319 }
318320
319321 struct CheckOptions
@@ -333,6 +335,20 @@ class TestSimplifyTemplate : public TestFixture {
333335 return tokenizer.tokens ()->stringifyList (nullptr , true );
334336 }
335337
338+ #define dump (...) dump_(__FILE__, __LINE__, __VA_ARGS__)
339+ template <size_t size>
340+ std::string dump_ (const char * file, int line, const char (&code)[size], const CheckOptions& options = make_default_obj()) {
341+ const Settings settings1 = settingsBuilder (settings).library (" std.cfg" ).debugwarnings (options.debugwarnings ).build ();
342+ SimpleTokenizer tokenizer (settings1, *this );
343+
344+ ASSERT_LOC (tokenizer.tokenize (code), file, line);
345+
346+ std::ostringstream ostr;
347+ (tokenizer.dump )(ostr);
348+
349+ return ostr.str ();
350+ }
351+
336352 void template1 () {
337353 const char code[] = " template <class T> T f(T val) { T a; }\n "
338354 " f<int>(10);" ;
@@ -6623,6 +6639,30 @@ class TestSimplifyTemplate : public TestFixture {
66236639 " class Test<64> { uint32_t i ; i = ( uint32_t ) 64 ; } ;" ,
66246640 tok (code));
66256641 }
6642+
6643+ void dumpTemplateArgFrom () {
6644+ const char code[] = " template<class T> void foo(T t) {}\n "
6645+ " foo<int>(23);" ;
6646+ const std::string d = dump (code);
6647+ ASSERT (!d.empty ());
6648+
6649+ // Assert that first 'int' token has templateArg location info
6650+ const std::string::size_type strpos1 = d.find (" str=\" int\" " );
6651+ ASSERT (strpos1 < d.size ());
6652+ const std::string::size_type endpos1 = d.find (' >' , strpos1);
6653+ const std::string::size_type templateArgPos1 = d.find (" templateArgFileIndex=\" 0\" templateArgLineNumber=\" 2\" templateArgColumn=\" 5\" " );
6654+ ASSERT (templateArgPos1 > strpos1 && templateArgPos1 < endpos1);
6655+
6656+ // Assert that second 'int' token has templateArg location info
6657+ const std::string::size_type strpos2 = d.find (" str=\" int\" " , endpos1);
6658+ ASSERT (strpos2 < d.size ());
6659+ const std::string::size_type endpos2 = d.find (' >' , strpos2);
6660+ const std::string::size_type templateArgPos2 = d.find (" templateArgFileIndex=\" 0\" templateArgLineNumber=\" 2\" templateArgColumn=\" 5\" " , endpos1);
6661+ ASSERT (templateArgPos2 > strpos2 && templateArgPos2 < endpos2);
6662+
6663+ // Assert there is no further unexpected templateArg location info
6664+ ASSERT (d.find (" templateArg" , endpos2) == std::string::npos);
6665+ }
66266666};
66276667
66286668REGISTER_TEST (TestSimplifyTemplate)
0 commit comments