From eade2bb2c29842edfcce3701c233930b8a50f34c Mon Sep 17 00:00:00 2001 From: IOBYTE Date: Thu, 9 May 2019 03:52:18 -0400 Subject: [PATCH] Add support for simplifying user defined literal operator. (#1827) --- lib/tokenize.cpp | 5 +++++ test/testtokenize.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a5b09f62e..c9bc35977 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -10543,6 +10543,11 @@ void Tokenizer::simplifyOperatorName() op += ")"; par = par->next(); done = false; + } else if (Token::Match(par, "\"\" %name% (")) { + op += "\"\""; + op += par->strAt(1); + par = par->tokAt(2); + done = true; } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 99022fd44..2c51bd322 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -398,6 +398,7 @@ private: TEST_CASE(simplifyOperatorName10); // #8746 - using a::operator= TEST_CASE(simplifyOperatorName11); // #8889 TEST_CASE(simplifyOperatorName12); // #9110 + TEST_CASE(simplifyOperatorName13); // user defined literal TEST_CASE(simplifyNullArray); @@ -6227,6 +6228,12 @@ private: tokenizeAndStringify(code)); } + void simplifyOperatorName13() { // user defined literal + const char code[] = "unsigned long operator""_numch(const char *ch, unsigned long size);"; + ASSERT_EQUALS("unsigned long operator""_numch ( const char * ch , unsigned long size ) ;", + tokenizeAndStringify(code)); + } + void simplifyNullArray() { ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); }