From 49e2573b5c49e4eebdb94eba1ddb279d41e8dd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Tue, 8 Sep 2015 15:11:17 +0200 Subject: [PATCH] fix -Wodr warning/violation putting struct 'VarInfo' into anonyous namespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was: lib/checkclass.cpp:1994:8: warning: type ‘struct VarInfo’ violates one definition rule [-Wodr] struct VarInfo { ^ lib/checkleakautovar.h:32:7: note: a different type is defined in another translation unit class CPPCHECKLIB VarInfo { ^ lib/checkclass.cpp:1998:21: note: the first difference of corresponding definitions is field ‘var’ const Variable *var; ^ lib/checkleakautovar.h:40:39: note: a field with different name is defined in another translation unit std::map alloctype; --- lib/checkclass.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 660a84e9d..8ab9620a0 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1991,13 +1991,15 @@ void CheckClass::checkConstError2(const Token *tok1, const Token *tok2, const st // ClassCheck: Check that initializer list is in declared order. //--------------------------------------------------------------------------- -struct VarInfo { - VarInfo(const Variable *_var, const Token *_tok) - : var(_var), tok(_tok) { } +namespace { // avoid one-definition-rule violation + struct VarInfo { + VarInfo(const Variable *_var, const Token *_tok) + : var(_var), tok(_tok) { } - const Variable *var; - const Token *tok; -}; + const Variable *var; + const Token *tok; + }; +} void CheckClass::initializerListOrder() {