|
24 | 24 | #include "token.h" |
25 | 25 | #include "tokenize.h" |
26 | 26 |
|
| 27 | +#include <simplecpp.h> |
| 28 | + |
27 | 29 | #include <sstream> // IWYU pragma: keep |
28 | 30 | #include <string> |
29 | 31 |
|
@@ -92,20 +94,33 @@ class TestSimplifyUsing : public TestFixture { |
92 | 94 | TEST_CASE(simplifyUsing10172); |
93 | 95 | TEST_CASE(simplifyUsing10173); |
94 | 96 | TEST_CASE(simplifyUsing10335); |
| 97 | + TEST_CASE(simplifyUsing10720); |
95 | 98 |
|
96 | 99 | TEST_CASE(scopeInfo1); |
97 | 100 | TEST_CASE(scopeInfo2); |
98 | 101 | } |
99 | 102 |
|
100 | 103 | #define tok(...) tok_(__FILE__, __LINE__, __VA_ARGS__) |
101 | | - std::string tok_(const char* file, int line, const char code[], cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true) { |
| 104 | + std::string tok_(const char* file, int line, const char code[], cppcheck::Platform::Type type = cppcheck::Platform::Type::Native, bool debugwarnings = true, bool preprocess = false) { |
102 | 105 | errout.str(""); |
103 | 106 |
|
104 | 107 | settings0.certainty.enable(Certainty::inconclusive); |
105 | 108 | settings0.debugwarnings = debugwarnings; |
106 | 109 | PLATFORM(settings0.platform, type); |
107 | 110 | Tokenizer tokenizer(&settings0, this); |
108 | 111 |
|
| 112 | + if (preprocess) { |
| 113 | + std::vector<std::string> files{ "test.cpp" }; |
| 114 | + std::istringstream istr(code); |
| 115 | + const simplecpp::TokenList tokens1(istr, files, files[0]); |
| 116 | + |
| 117 | + simplecpp::TokenList tokens2(files); |
| 118 | + std::map<std::string, simplecpp::TokenList*> filedata; |
| 119 | + simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI()); |
| 120 | + |
| 121 | + tokenizer.createTokens(std::move(tokens2)); |
| 122 | + } |
| 123 | + |
109 | 124 | std::istringstream istr(code); |
110 | 125 | ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line); |
111 | 126 |
|
@@ -1346,6 +1361,17 @@ class TestSimplifyUsing : public TestFixture { |
1346 | 1361 | ASSERT_EQUALS(exp, tok(code)); |
1347 | 1362 | } |
1348 | 1363 |
|
| 1364 | + void simplifyUsing10720() { |
| 1365 | + const char code[] = "template <typename... Ts>\n" |
| 1366 | + "struct S {};\n" |
| 1367 | + "#define STAMP(thiz, prev) using thiz = S<prev, prev, prev, prev, prev, prev, prev, prev, prev, prev>;\n" |
| 1368 | + "STAMP(A, int);\n" |
| 1369 | + "STAMP(B, A);\n" |
| 1370 | + "STAMP(C, B);\n"; |
| 1371 | + tok(code, cppcheck::Platform::Type::Native, /*debugwarnings*/ true, /*preprocess*/ true); |
| 1372 | + ASSERT_EQUALS(errout.str().compare(0, 64, "[test.cpp:6]: (debug) Failed to parse 'using C = S < S < S < int"), 0); |
| 1373 | + } |
| 1374 | + |
1349 | 1375 | void scopeInfo1() { |
1350 | 1376 | const char code[] = "struct A {\n" |
1351 | 1377 | " enum class Mode { UNKNOWN, ENABLED, NONE, };\n" |
|
0 commit comments