If I pass a double to a function requiring long, g++ warns of conversion problem, but if I pass a const double to a function requiring long, g++ is happy. The warning is the following:
warning: conversion to ‘long int’ from ‘double’ may alter its value [-Wconversion]
I would like g++ to give me a warning whether I pass a double or a const double. How would I do so?
I have makefile and some code you can run. I like to turn on as many warnings as I can, but perhaps one is implicitly shutting off another? I'm not sure.
Here's the Makefile:
WARNOPTS=-Wall -Wextra -pedantic \
-Wdouble-promotion -Wformat=2 -Winit-self \
-Wmissing-include-dirs -Wswitch-default -Wswitch-enum \
-Wundef -Wunused-function -Wunused-parameter \
-Wno-endif-labels -Wshadow \
-Wpointer-arith \
-Wcast-qual -Wcast-align \
-Wconversion \
-Wsign-conversion -Wlogical-op \
-Wmissing-declarations -Wredundant-decls \
-Wctor-dtor-privacy \
-Wnarrowing -Wnoexcept -Wstrict-null-sentinel \
-Woverloaded-virtual \
-Wsign-compare -Wsign-promo -Weffc++
BUILD := develop
cxxflags.develop := -g $(WARNOPTS)
cxxflags.release :=
CXXFLAGS := ${cxxflags.${BUILD}}
foo: foo.cpp
g++ $(CXXFLAGS) -o $@ $^
Here's foo.cpp:
// foo.cpp
#include <iostream>
#include <string>
using namespace std;
const double WAITTIME = 15; // no warning on function call
//double WAITTIME = 15; // warning on function call
bool funcl( long time);
bool funcl( long time ) {
cout << "time = " << time << endl;
return true;
}
int main() {
string rmssg;
funcl( WAITTIME );
return 0;
}
This is the version of g++ that I am using:
g++ --version
g++ (Debian 4.7.2-5) 4.7.2
Thanks for the help!