The C++ compiler (gcc version 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) (GCC)) doesn't issue expected warning when converting long long to int (see the code example below).
// compiler: gcc version 4.4.7 20120313 (Red Hat 4.4.7-23.0.1) (GCC)
// compiled with flags -pedantic -Wextra -Wshadow -Wall -Wconversion -std=gnu++0x
#include <stdio.h>
class AConv {
public:
long long z() {
return 7634843234L;
}
void p() {
const int v = z(); // NO WARNING. WHY ? See next line which calls the same function.
const int w = this->z(); // compiler warning: conversion to 'int' from 'long long int' may alter its value
printf( "v=%d, w=%d\n", v, w); // butchered values shown
}
};
I find this behavior counter-intuitive.
Is it a g++ - only feature?
I'd like to force the compiler to generate warning for both invocations, not just for the second one:
v = z();
w = this->z();
I cannot upgrade the compiler (I work in a corporate environment with constraints).