public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "bogdasar1985 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-104397-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104397 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=52355&action=edit 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 <stdio.h> 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: ‘a’ 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 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "class.hpp" static int a; class Class { public: Class(); ~Class(); private: int b; int c; }; main.ii ------------- # 1 "main.cpp" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "main.cpp" #pragma GCC pch_preprocess "class.hpp.gch" int main() { Class a, b, c, d; return 0; }
next reply other threads:[~2022-02-05 9:29 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-05 9:29 bogdasar1985 at gmail dot com [this message] 2022-02-05 9:37 ` [Bug c++/104397] " pinskia at gcc dot gnu.org 2022-02-05 13:08 ` jakub at gcc dot gnu.org 2022-02-07 7:50 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-104397-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).