From 87b69a10fa1f743709c981ccae7c1eaf3ac31981 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 27 Nov 2010 10:17:03 +0200 Subject: [PATCH] Ticket #2240 (Improve no constructor-message). Improve the message about missing constructor but having class attributes. Have proper short and long messages. --- lib/checkclass.cpp | 6 +++++- test/testclass.cpp | 2 +- test/testconstructors.cpp | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 22576ac58..a1904ff8f 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -164,7 +164,11 @@ void CheckClass::constructors() void CheckClass::noConstructorError(const Token *tok, const std::string &classname, bool isStruct) { // For performance reasons the constructor might be intentionally missing. Therefore this is not a "warning" - reportError(tok, Severity::style, "noConstructor", "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + "' has no constructor. Member variables not initialized."); + reportError(tok, Severity::style, "noConstructor", + "The " + std::string(isStruct ? "struct" : "class") + " '" + classname + + "' does not have a constructor.\n" + "The class 'classname' does not have a constructor but it has attributes. " + "The attributes are not initialized which may cause bugs or undefined behavior."); } void CheckClass::uninitVarError(const Token *tok, const std::string &classname, const std::string &varname) diff --git a/test/testclass.cpp b/test/testclass.cpp index e60e51c67..4662bf768 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2539,7 +2539,7 @@ private: "{\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' has no constructor. Member variables not initialized.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str()); } void noConstructor2() diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 8e1ccdb79..b4350cb0d 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -96,7 +96,7 @@ private: "private:\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' has no constructor. Member variables not initialized.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str()); check("struct Fred\n" "{\n" @@ -109,7 +109,7 @@ private: "private:\n" " int i;\n" "};\n"); - ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' has no constructor. Member variables not initialized.\n", errout.str()); + ASSERT_EQUALS("[test.cpp:1]: (style) The struct 'Fred' does not have a constructor.\n", errout.str()); }