From d75331d00d32b632c0c1a146a5bcf88a521b4a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Jun 2023 11:43:07 +0200 Subject: [PATCH] Fix #11435 (FP ctuOneDefinitionRuleViolation for template specialization) (#5156) --- lib/checkclass.cpp | 3 +++ test/testclass.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 3a6bc79d0..15b102068 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -3158,6 +3158,9 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti if (classScope->isAnonymous()) continue; + if (classScope->classDef && Token::simpleMatch(classScope->classDef->previous(), ">")) + continue; + // the full definition must be compared const bool fullDefinition = std::all_of(classScope->functionList.cbegin(), classScope->functionList.cend(), diff --git a/test/testclass.cpp b/test/testclass.cpp index 93d85a623..c9ddee6b2 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -8546,6 +8546,12 @@ private: ctu({"class A::C { C() { std::cout << 0; } };", "class B::C { C() { std::cout << 1; } };"}); ASSERT_EQUALS("", errout.str()); + + // 11435 - template specialisations + const std::string header = "template struct Test {};\n"; + ctu({header + "template struct Test {};\n", + header + "template struct Test {};\n"}); + ASSERT_EQUALS("", errout.str()); }