PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] How can I make GCC/Clang warn about the use of uninitialized members?

 April 28, 2022     c++, clang, gcc, warnings     No comments   

Issue

I am compiling the code behind

class Test {
public:
    Test() {}

    int k;
};

int main() {
  Test t;
  std::cout << t.k << "\n";
}

like

g/clang++ main.cpp -Wall -Wextra --std=c++14 -o exe; ./exe

Why neither of the compilers does not warn me about indeterminate value of the integer is not it a very serious potential bug? How to enable a warning for indeterminate initializations?


Solution

For this example, GCC gives me the desired warning when I give it -O1 (or higher).

Presumably whatever mechanism it uses to detect this is tied into the optimisation effort level somehow. It's a notoriously hard thing to do.

Ensure that you heed your release-build warnings as well as debug-build warnings.



Answered By - Lightness Races in Orbit
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing