From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 972E53858D28; Sat, 5 Feb 2022 09:29:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 972E53858D28 From: "bogdasar1985 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp) Date: Sat, 05 Feb 2022 09:29:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bogdasar1985 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 05 Feb 2022 09:29:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104397 Bug ID: 104397 Summary: Wrong warning message about global static variable in module(.hpp, .cpp) Product: gcc Version: 9.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bogdasar1985 at gmail dot com Target Milestone: --- Created attachment 52355 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D52355&action=3Dedit Output of "gcc -v -save-temps all-your-options source-file && neofetch --stdout" class.hpp ------------- #ifndef CLASS #define CLASS static int a; class Class { public: Class(); ~Class(); private: int b; int c; }; #endif class.cpp --------------- #include "class.hpp" #include Class::Class() : b(0), c(0) { a++; printf("%d\n", a); }; Class::~Class() { printf("%d\n", a); a--; } main.cpp ------------- #include "class.hpp" int main() { Class a, b, c, d; return 0; } Compiling that by command: g++ -Wall class.hpp class.cpp main.cpp -o main generate next warning: class.hpp:3:12: warning: =E2=80=98a=E2=80=99 defined but not used [-Wunused= -variable] 3 | static int a; | ^ which is wrong, because variable a used for output. Output of gcc -v -save-temps all-your-options source-file && neofetch --stdout in attachment file. class.ii ------------ # 1 "class.hpp" # 1 "" # 1 "" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "" 2 # 1 "class.hpp" static int a; class Class { public: Class(); ~Class(); private: int b; int c; }; main.ii ------------- # 1 "main.cpp" # 1 "" # 1 "" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "" 2 # 1 "main.cpp" #pragma GCC pch_preprocess "class.hpp.gch" int main() { Class a, b, c, d; return 0; }=