From 1a58ae4994f2a7b0577838f96a94e502af5667ee Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 1 Feb 2013 06:31:02 +0100 Subject: [PATCH] Symbol database: handle when forward declaration doesn't match declaration. Ticket: #4531 --- lib/symboldatabase.cpp | 10 ++++++++++ test/testconstructors.cpp | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 859b34e42..a7dd01546 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -88,6 +88,16 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti break; } } + + // definition may be different than declaration + if (tok->str() == "class") { + access[new_scope] = Private; + new_scope->type = Scope::eClass; + } else if (tok->str() == "struct") { + access[new_scope] = Public; + new_scope->type = Scope::eStruct; + } + back[tok2->link()] = scope; new_scope->classDef = tok; new_scope->classStart = tok2; diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index c55a88336..7e0470935 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -59,6 +59,7 @@ private: TEST_CASE(simple4); TEST_CASE(simple5); // ticket #2560 TEST_CASE(simple6); // ticket #4085 - uninstantiated template class + TEST_CASE(simple7); // ticket #4531 TEST_CASE(initvar_with_this); // BUG 2190300 TEST_CASE(initvar_if); // BUG 2190290 @@ -302,6 +303,14 @@ private: "[test.cpp:3]: (warning) Member variable 'A::y' is not initialized in the constructor.\n", errout.str()); } + void simple7() { // ticket #4531 + check("class Fred;\n" + "struct Fred {\n" + " int x;\n" + "};"); + ASSERT_EQUALS("", errout.str()); + } + void initvar_with_this() { check("struct Fred\n" "{\n"