public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp)
@ 2022-02-05 9:29 bogdasar1985 at gmail dot com
2022-02-05 9:37 ` [Bug c++/104397] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: bogdasar1985 at gmail dot com @ 2022-02-05 9:29 UTC (permalink / raw)
To: gcc-bugs
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;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/104397] Wrong warning message about global static variable in module(.hpp, .cpp)
2022-02-05 9:29 [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp) bogdasar1985 at gmail dot com
@ 2022-02-05 9:37 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-02-05 9:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104397
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2022-02-05
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This does not use modules though:
g++ -Wall class.hpp class.cpp main.cpp -o main
This just uses precompiled headers.
As shown by:
#pragma GCC pch_preprocess "class.hpp.gch"
This means the a is defined but not used.
See
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/C_002b_002b-Modules.html#C_002b_002b-Modules
on how to use modules rather than precompiled headers.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/104397] Wrong warning message about global static variable in module(.hpp, .cpp)
2022-02-05 9:29 [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp) bogdasar1985 at gmail dot com
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
2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-02-05 13:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104397
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The warning is correct.
While static int a; var is used in class.cpp, you have another copy of that in
the main.cpp TU, and there it is defined but unused.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/104397] Wrong warning message about global static variable in module(.hpp, .cpp)
2022-02-05 9:29 [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp) bogdasar1985 at gmail dot com
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
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-07 7:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104397
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|WAITING |RESOLVED
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Thus invalid.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-07 7:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-05 9:29 [Bug c++/104397] New: Wrong warning message about global static variable in module(.hpp, .cpp) bogdasar1985 at gmail dot com
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
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).