Bug 45385 - [4.4/4.5/4.6 Regression] missing -Wconversion for method calls
Summary: [4.4/4.5/4.6 Regression] missing -Wconversion for method calls
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.3
: P3 normal
Target Milestone: 4.7.0
Assignee: Paolo Carlini
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2010-08-23 16:06 UTC by Gaetano Mendola
Modified: 2011-11-13 16:36 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.6.0
Last reconfirmed: 2010-08-25 11:12:45


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gaetano Mendola 2010-08-23 16:06:17 UTC
Hi,
compiling the following code with -Wconversion doesn't give a warning while with compiler version 4.3.2 does. As you can verify the posted code has a real conversion loss at runtime giving:

expected: 8000000000
obtained: 3705032704


=================================================================
#include <iostream>

void foo(unsigned int a) { std::cout << "obtained: " << a << std::endl; }

class Test {
public:
  void eval() {
    foo(bar());
  }
private:
    unsigned long long bar() const {
      unsigned long long ret = 8000000000;
      std::cout << "expected: " << ret << std::endl;
      return ret;
    }
};

int main () {
    Test t;
    t.eval();

    return 1;
}
=================================================================
Comment 1 Andrew Pinski 2010-08-25 11:12:43 UTC
Confirmed, if I make bar() a non class function, we get the warning.
Comment 2 Paolo Carlini 2011-10-20 01:25:23 UTC
Manuel, I seem to remember you did some work in this area?!?
Comment 3 Manuel López-Ibáñez 2011-10-20 08:19:05 UTC
There is a check in c-common.c:conversion_warning that tests for things generated by the compiler by looking for artificial operands. The implicit *this pointer is probably triggering here. One could test for *this or perhaps there is a better way to check for compiler-generated expressions (if you remove the check, you should trigger a regression in the testsuite).
Comment 4 Paolo Carlini 2011-10-20 08:27:38 UTC
Thanks a lot. If I understand correctly this is a regression affecting a very sensible warning which we want to fix for 4.7, at least. We should mark it as such.
Comment 5 paolo@gcc.gnu.org 2011-10-21 20:01:34 UTC
Author: paolo
Date: Fri Oct 21 20:01:31 2011
New Revision: 180312

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180312
Log:
/cp
2011-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/45385
	* init.c (build_vec_init): Early return error_mark_node if
	maxindex is -1.

/c-family
2011-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/45385
	* c-common.c (conversion_warning): Remove code looking for
	artificial operands.

/testsuite
2011-10-21  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/45385
	* g++.dg/warn/Wconversion4.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/warn/Wconversion4.C
Modified:
    trunk/gcc/c-family/ChangeLog
    trunk/gcc/c-family/c-common.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Paolo Carlini 2011-10-21 20:02:53 UTC
Fixed for 4.7.0 so far.
Comment 7 Paolo Carlini 2011-11-13 16:36:53 UTC
Fixed for 4.7.0.