Search code examples
c++codeblockscompiler-warningstype-narrowing

How to enable narrowing warnings in CodeBlocks?


I'm writing c++ program using codeblocks IDE

int main()
{
int i =0;
int f = 3.14;
i = f; //must give me a warning message, possible loss data.
}

Why the compilation not show a narrowing warning message? How to enable that?

Note: I have fixed my compiler options as -std=c++11 -Wall


Solution

  • in the other compiler options put -Wconversion

    ( code::block 16 )

    enter image description here

    for:

    int i =0;
    int f = 3.14;
    i = f;
    

    warning: conversion to ‘int’ alters ‘double’ constant value [-Wfloat-conversion]


    Some useful warning that I use always:

    enter image description here

    -Wall -Weffc++ -Wextra -pedantic -Wfatal-errors -pedantic-errors