1

I can't see almost any warnings in my program.

My cpp file:

#include <iostream> using namespace std; int main() { long long int ll = 100000000067; unsigned short sh = ll; //no warning here, why? cout << sh << " " << ll << endl; int s; //warning only here: warning: unused variable ‘s’ [-Wunused-variable] return 0; } 

My pro file:

TEMPLATE = app CONFIG += console c++11 CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp QMAKE_CXXFLAGS += -Wall -Wextra -pedantic 

I try use project with cmake, but the results are this same.

4
  • What was the compiler that you used ? Commented Dec 11, 2016 at 13:53
  • in option -> build & run -> compilers I have only: auto-detected GCC 64/32 bit. I use 64bit by default. Commented Dec 11, 2016 at 14:02
  • What is your GCC version? Type gcc --version in terminal. Commented Dec 11, 2016 at 14:05
  • gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609 Commented Dec 11, 2016 at 14:06

1 Answer 1

2

According to GCC documentation

-Wconversion

Warn for implicit conversions that may alter a value. This includes conversions between real and integer, like abs (x) when x is double; conversions between signed and unsigned, like unsigned ui = -1; and conversions to smaller types, like sqrtf (M_PI). Do not warn for explicit casts like abs ((int) x) and ui = (unsigned) -1, or if the value is not changed by the conversion like in abs (2.0). Warnings about conversions between signed and unsigned integers can be disabled by using -Wno-sign-conversion. For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that never use a type conversion operator: conversions to void, the same type, a base class or a reference to them. Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

For me your example with -Wconversion generates

~/main.cpp:9: warning: conversion to 'short unsigned int' from 'long long int' may alter its value [-Wconversion] unsigned short sh = ll; //no warning here, why? ^ 
Sign up to request clarification or add additional context in comments.

1 Comment

I'm surprised this is not covered by (any or all of) -Wall -Wextra -pedantic!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.