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

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).