This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81557] New: Detect unused const char * and STL string


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81557

            Bug ID: 81557
           Summary: Detect unused const char * and STL string
           Product: gcc
           Version: 5.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jg at jguk dot org
  Target Milestone: ---

Would be great if GCC could detect warnings on line 10 and 12 in this unused
code code

Expected something like

$ g++ -Wall -o main main.cpp
main.cpp: In function ‘int main()’:
main.cpp:10:15: warning: ‘str’ replaced earlier initialization on line 9 that
was unused 
     str = "second";
     ^
main.cpp:12:15: warning: ‘str2’ replaced earlier initialization on line 12 that
was unused 
     str2 = "third";



//g++ -O2 -Wall -Wextra -Wpedantic -o main main.cpp

#include <string>
#include <stdio.h>

int main (void)
{
    const char * str = "mystr";
    str = "second";

    std::string str2 = "test";
    str2 = "third";

    printf("%s %s\n", str, str2.c_str());

    return 0;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]