From acaa9c456fcb37f273734371e77bd0cb86bf407e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 Oct 2011 19:45:47 +0200 Subject: [PATCH] Fixed #3152 (Tokenizer: template constructor is removed) --- lib/tokenize.cpp | 7 +++++++ test/testsimplifytokens.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a10f9117d..172022f28 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2624,6 +2624,13 @@ static void removeTemplates(Token *tok) tok->str(";"); break; } + // don't remove constructor + if (tok2->str() == "explicit") + { + Token::eraseTokens(tok, tok2); + tok->str(";"); + break; + } if (tok2->str() == "(") { tok2 = tok2->link(); if (!tok2) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 8b0ab083c..f473a9616 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -120,6 +120,7 @@ private: TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); TEST_CASE(template_typename); + TEST_CASE(template_constructor); // #3152 - template constructor is removed TEST_CASE(namespaces); @@ -2255,6 +2256,15 @@ private: } } + void template_constructor() { + // #3152 - if template constructor is removed then there might be + // "no constructor" false positives + const char code[] = "class Fred {\n" + " template explicit Fred(T t) { }\n" + "}"; + ASSERT_EQUALS("class Fred { ; explicit Fred ( T t ) { } }", tok(code)); + } + void namespaces() { { const char code[] = "using namespace std; namespace a{ namespace b{ void f(){} } }";