Partial fix for #11378 (iscpp11init) (#4595)

* Partial fix for #11378 (iscpp11init)

* Improve fix

* Add fix
This commit is contained in:
chrchr-github 2022-11-27 09:26:46 +01:00 committed by GitHub
parent 665e4230f2
commit 428f5016d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -8889,7 +8889,7 @@ void Tokenizer::simplifyNamespaceStd()
if (Token::Match(tok, "enum class|struct| %name%| :|{")) { // Don't replace within enum definitions
skipEnumBody(&tok);
}
if (!Token::Match(tok->previous(), ".|::")) {
if (!Token::Match(tok->previous(), ".|::|namespace")) {
if (Token::Match(tok, "%name% (")) {
if (isFunctionHead(tok->next(), "{"))
userFunctions.insert(tok->str());

View File

@ -691,7 +691,7 @@ static bool iscpp11init_impl(const Token * const tok)
if (!Token::simpleMatch(endtok, "} ;"))
return true;
const Token *prev = nameToken;
while (Token::Match(prev, "%name%|::|:|<|>|,")) {
while (Token::Match(prev, "%name%|::|:|<|>|,|%num%")) {
if (Token::Match(prev, "class|struct|union|enum"))
return false;

View File

@ -7506,6 +7506,32 @@ private:
testIsCpp11init("enum { e = decltype(s)::i };",
"{ e",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("template <typename T>\n" // #11378
"class D<M<T, 1>> : public B<M<T, 1>, T> {\n"
"public:\n"
" D(int x) : B<M<T, 1>, T>(x) {}\n"
"};\n",
"{ public:",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("template <typename T>\n"
"class D<M<T, 1>> : B<M<T, 1>, T> {\n"
"public:\n"
" D(int x) : B<M<T, 1>, T>(x) {}\n"
"};\n",
"{ public:",
TokenImpl::Cpp11init::NOINIT);
testIsCpp11init("using namespace std;\n"
"namespace internal {\n"
" struct S { S(); };\n"
"}\n"
"namespace internal {\n"
" S::S() {}\n"
"}\n",
"{ } }",
TokenImpl::Cpp11init::NOINIT);
#undef testIsCpp11init
}
};